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<http://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