AD Latency and Exchange Powershell
When I used combination of cmdlet create a bulk mailbox and modify attribute e.g. company, title and etc. Sometime, it was failed to modify certain new user with error user not found. I find this link
http://unlockpowershell.wordpress.com/2010/01/08/powershell-dealing-with-active-directory-latency/ which i believe the root cause.
I tried create cmdlet with combination of -DomainController, it work
foreach ($user in $users)
{
New-Mailbox -Name $user.name -FirstName $user.firstname -LastName $user.lastname -Alias $user.alias -UserPrincipalName ($user.alias +'@contoso') -Database $user.database -OrganizationalUnit $user.org -Password ( ConvertTo-SecureString sst2011 -AsPlainText -Force) -ResetPasswordOnNextLogon:$false -DomainController dc03.contoso.com
Set-User -Identity $user.alias -Company $user.Comp -Title $user.title -Department $user.department -Manager $user.manager -Office $user.office -DomainController dc03.contoso.com
Add-DistributionGroupMember $user.groups -Member $user.alias -DomainController DC03.contoso.com
}
However, i try to use do...while but I'm stuck please help.
$users = Import-Csv c:\ps\CreateMailbox.csv
foreach ($user in $users)
{
New-Mailbox -Name $user.name -FirstName $user.firstname -LastName $user.lastname -Alias $user.alias -UserPrincipalName ($user.alias +'@contoso') -Database $user.database -OrganizationalUnit $user.org -Password ( ConvertTo-SecureString sst2011 -AsPlainText -Force) -ResetPasswordOnNextLogon:$false
do
{
Get-Mailbox -Identity $user.alias -ErrorAction SilentlyContinue
}
While ($users.alias -eq $null)
Set-User -Identity $user.alias -Company $user.Comp -Title $user.title -Department $user.department -Manager $user.manager -Office $user.office
Add-DistributionGroupMember $user.groups -Member $user.alias
}
March 30th, 2011 6:37am
Try (untested)
do
{
$mailbox = Get-Mailbox -Identity
$user.alias -ErrorAction SilentlyContinue
}
While ($mailbox -eq
$null)
Karl
http://unlockpowershell.wordpress.com
-join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
Free Windows Admin Tool Kit Click here and download it now
March 31st, 2011 12:54pm