I have sleep command in the script, that could make the script run for 30 minutes. If the powershell script runs for long time, would it get stuck? The script completes sometimes, but sometimes, it is just postprocessing.
param( $AcctName, $OwnerName)
Import-Module ActiveDirectory
$ADUser = Get-ADUser -LDAPFilter "(sAMAccountName=$AcctName)" -SearchBase "OUpath" -Server "dcname"
while ($ADUser -eq $Null){
Start-Sleep -Second 180
$ADUser = Get-ADUser -LDAPFilter "(sAMAccountName=$AcctName)" -SearchBase "OUpath" -Server "dcname"
}
If($ADUser -ne $Null)
{
Start-Sleep -Second 360
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
Set-mailbox $AcctName -Type Shared
Add-MailboxPermission -Identity $AcctName -User $OwnerName -AccessRights 'FullAccess'
}