OK, Thank you.
Now I find that a couple of accounts do not have an email address. To
bypass them do I test for WindowsEmailAddress being not null right before
foreach or part of the foreach statement.
Like.... If (WindowsEmailAddress not null) { $UPN = }
I am used to IF then next else end.
Todd Lemmiksoo
On Thu, Nov 20, 2014 at 3:35 PM, Michael B. Smith <[email protected]>
wrote:
> You are close.
>
>
>
> $users = Get-User –OrganizationalUnit “OU=Information
> Technology,OU=BR-General,OU=Employees,OU=Accounts,DC=ghsbtr,DC=net”
> -ResultSize Unlimited
> foreach ($user in $users)
> {
> $UPN = $user.WindowsEmailAddress.ToString()
> Write-Host "Setting " $UPN
> $user | Set-User -UserPrincipalName $UPN
> }
>
>
>
> *From:* [email protected] [mailto:
> [email protected]] *On Behalf Of *Todd Lemmiksoo
> *Sent:* Thursday, November 20, 2014 3:57 PM
> *To:* [email protected]
> *Subject:* [Exchange] Powershell help
>
>
>
> I am using a powershell script to update the UPN in AD for our Office 365
> migration. Below is the script.
>
>
> #
> $users = Get-User -Filter "distinguishedName -like 'CN=*,OU=Information
> Technology,OU=BR-General,OU=Employees,OU=Accounts,DC=ghsbtr,DC=net'"
> -ResultSize Unlimited
> foreach ($user in $users)
> {
> $UPN = "$($user.WindowsEmailAddress)"
> Write-Host "Setting " $UPN
> $user | Set-User -UserPrincipalName $UPN
> }
>
>
>
> It errors out with this error:
> Setting
> Invoke-Command : Cannot bind parameter 'UserPrincipalName' to the target.
> Exception setting "UserPrincipalName": "The p
> roperty can't be empty."
> At C:\Users\lemmitt99\AppData\Roaming\Microsoft\Exchange\RemotePowerShell\
> ghsmsasex1.ghsbtr.net\ghsmsasex1.ghsbtr.net.p
> sm1:60853 char:29
> + $scriptCmd = { & <<<< $script:InvokeCommand `
> + CategoryInfo : WriteError: (:) [Set-User],
> ParameterBindingException
> + FullyQualifiedErrorId :
> ParameterBindingFailed,Microsoft.Exchange.Management.RecipientTasks.SetUser
>
> Everyone in the IT OU has an email address.
>
> --
>
> T. Todd Lemmiksoo
>
--
T. Todd Lemmiksoo