|
Replies:
4
-
Pages:
1
-
Last Post:
Apr 5, 2012 9:44 AM
by: GregVM
|
|
|
Posts:
49
Registered:
3/16/09
|
|
|
|
Can you build a delay in a powershell script?
Posted:
Oct 15, 2009 8:24 AM
|
|
|
My script works fine until I get to the last line where I enabled it as a distribution group in exchange. I get the error message that says:
The recipient "playlsi.com/test/testmail" could not be read from domain controller "dln1001p.playlsi.com". This may be due to replication delays. Switching out of Forest mode should allow this operation to complete successfully. At :line:16 char:25 + Enable-DistributionGroup <<<< $name -PrimarySmtpAddress $email
If I do the last line 10 seconds later it works fine. I think if I delay the last line a few seconds the whole script will work flawlessly.
Here is my script:
$GroupName = Read-Host -Prompt 'Enter Group Name' #OU where to look for OUs $OU = "OU=test,DC=Playlsi,DC=com" #Gets a list of all OUs inside $OU get-qadobject -type OrganizationalUnit -sizeLimit 0 -searchRoot $ou | # Exclude the parent container where {$_.ParentContainerDN -eq $ou } |
foreach { $name = $_.name -replace "_.*$","_" + $GroupName $email = $name + "@playlsi.com" New-QADGroup -ParentContainer $OU -Name $name -DisplayName $name -samAccountName $name -GroupType Distribution -GroupScope Universal | Set-QADGroup -email $email #Mail enables so it appears in Exchange as a distribution group Enable-DistributionGroup $name -PrimarySmtpAddress $email }
|
|
|
Posts:
1,241
Registered:
12/1/06
|
|
|
|
Re: Can you build a delay in a powershell script?
Posted:
Oct 15, 2009 8:51 AM
in response to: Jon Reider
|
 |
Answered |
|
|
In PowerShell v1 you can add delay by doing:
[System.Threading.Thread]::Sleep(10000)
In PowerShell v2 there is a start-sleep cmdlet:
Start-Sleep -Second 10
|
|
|
Posts:
49
Registered:
3/16/09
|
|
|
|
Re: Can you build a delay in a powershell script?
Posted:
Oct 15, 2009 9:09 AM
in response to: Dmitry Sotnikov
|
|
|
Yup that worked perfectly. Thanks Dmitry!
|
|
|
Posts:
1
Registered:
4/4/12
|
|
|
|
Re: Can you build a delay in a powershell script?
Posted:
Apr 4, 2012 1:05 PM
in response to: Jon Reider
|
|
|
Can you share the location you added "[System.Threading.Thread]::Sleep(10000)" to your script? I'm really new to scripting sorry for the newbe question.
|
|
|
Posts:
732
Registered:
1/14/08
|
|
|
|
Re: Can you build a delay in a powershell script?
Posted:
Apr 5, 2012 9:44 AM
in response to: johnswb
|
|
|
This thread was already answered and closed. Please open a new thread and don't forget to include your code so the community has something to review for your question. Each script can have a myriad of goals, so providing your code helps us provide an accurate response.
thx
|
Greg Montoya
PowerGUI MVP
ActiveRoles Server MVP
|
|
|
Legend
|
|
MVP: 2501
+
pts
|
|
Guru: 2001
- 2500
pts
|
|
Expert: 751
- 2000
pts
|
|
Enthusiast: 31
- 750
pts
|
|
Novice: 0
- 30
pts
|
|
Moderators
|
|
Helpful answer
(5 pts)
|
|
Answered
(10 pts)
|
|