A cloud-based service included in Microsoft 365, delivering scalable messaging and collaboration features with simplified management and automatic updates.
Hi,
Can i get an update please?
Imran
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi, i created this script and it works but the issue i have is after creating the O365 mailbox i wanted to get a Add-MailboxFolderPermission command to add specific permissions and when it runs this command i get an error saying the account doesnt exist even when i add a start-sleep -miliseconds 1000.
Code:
#Installs AD modules
import-module activedirectory
#exchange snapin
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
# The Questions
Write-host "Please complete the following questions, Ensure spelling and case are accurate"
$First=Read-Host 'Enter First Name'
$Last=Read-Host 'Enter Last Name'
$Title=Read-Host 'Enter Job Title'
$username=Read-Host 'Enter Username'
$Department=Read-Host 'Enter the users department. Press Space then Enter if information is not available'
$manager=Read-Host 'Enter Managers UserName'
$Location=Read-Host 'Enter Office Location'
#Hidden Attributes
$Path="OU=Users,DC=domain,DC=com"
$SAMAccountName=$username
$DisplayName=$First+' '+$Last
$UserPrincipalName=$username+'@domain.com'
$Calendar=$username+':\Calendar'
$routing=$username+'@domain.com'
#This section prompts you to enter a password
$password=Read-Host "Enter Users Password" -AsSecureString
#AD Attributes
New-ADUser -SAMAccountName $SAMAccountName -name $DisplayName -GivenName $First -Surname $Last -UserPrincipalName $UserPrincipalName -DisplayName $DisplayName -Title $Title -Description $Title -Department $Department -Path $Path -Company $Company -Office $Location -OfficePhone $OfficePhone -Manager $Manager -HomeDirectory $HomeDrive
#Password
Set-ADAccountPassword -identity $SAMAccountName -NewPassword $password -Reset
Start-sleep -milliseconds 5000
Enable-ADAccount -Identity $SAMAccountName
#This section forces and AD to 365 Delta sync from the domain controller, then pauses the script to make sure the sync has completed.
Invoke-Command -Computer SyncServer01.domain.com -Scriptblock {Start-ADSyncSyncCycle -PolicyType Delta}
start-sleep -milliseconds 10000
#powershell to connect to O365
$O365Credentials = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $O365Credentials -Authentication Basic -AllowRedirection
Import-Module (Import-PSSession -Session $Session -AllowClobber -DisableNameChecking) -Global
# enable exchange
Enable-RemoteMailbox $username -RemoteRoutingAddress $routing
#Get-Mailbox information
Get-Mailbox $username
#add sleep in before calendar permissions
start-sleep -milliseconds 10000
#exchange calendar permissions
Add-MailboxFolderPermission $Calendar -User "User01" -AccessRights Reviewer
#now remove the connection to O365
Remove-PSSession $Session
###### HomeDrive
$HomeDrive = "\\Server01\HomeDrive\$username"
if (Test-Path $HomeDrive) {
Write-Host -ForegroundColor Yellow "
-------------------------------------------------------
`n
Account or parts of the setup have already been done.
`n
-------------------------------------------------------
"
}
else {
# create new folder
$null = New-Item -Path $HomeDrive -ItemType Directory
# get permissions
$acl = Get-Acl -Path $HomeDrive
# add a new permission (FullControl, Modify, Read)
$permission = $username, 'Full', 'ContainerInherit, ObjectInherit', 'None', 'Allow'
$rule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $permission
$acl.SetAccessRule($rule)
# set new permissions
$acl | Set-Acl -Path $HomeDrive
# verify the folder has been created
if (Test-Path $HomeDrive) {
Write-Host -ForegroundColor Green "
----------------------------
`n
Account Created successfully.
`n
----------------------------
"
}
else {
Write-Host -ForegroundColor Red "
--------------------------------
`n
The Account failed to create all or parts of its setup.
`n
--------------------------------
"
}
Set-ADUser -identity $username -HomeDrive $null -HomeDirectory $null
}
Any Help would be greatful. Thank you in advance
A cloud-based service included in Microsoft 365, delivering scalable messaging and collaboration features with simplified management and automatic updates.
Using classic Outlook for Windows in business environments
The process of building custom applications and tools that interact with Microsoft Exchange Server
The administration and maintenance of Microsoft Exchange Server to ensure secure, reliable, and efficient email and collaboration services across an organization.
Hi,
Can i get an update please?
Imran