none
AD Latency and Exchange Powershell RRS feed

  • Question

  • 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
    
    }
    
    • Moved by Alan.GimModerator Tuesday, April 5, 2011 6:43 AM script-related (From:Admin)
    Wednesday, March 30, 2011 10:32 AM

Answers

  • 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$_"})
    • Marked as answer by Suriya25 Monday, April 11, 2011 1:30 AM
    Thursday, March 31, 2011 4:53 PM