script to populate ProxyAddresses and Mail attribute based on the UserPrincipalName
Posted on 2014-08-12
I am trying to populate the ProxyAddresses AND mail attribute for ALL users based on their UserPrincipalName.
Need help with the following:
$UPN = Get-ADUser -Filter * |select UserPrincipalName
$user = Get-ADUser -Filter * -Properties mail,ProxyAddresses
$user.ProxyAddresses = ("SMTP:" + $UPN.UserPrincipalName),("SIP:" + $UPN.UserPrincipalName)
$user.mail = $UPN.UserPrincipalName
Set-ADUser -instance $user
It doesn't work, returns me this error:
The property 'ProxyAddresses' cannot be found on this object. Verify that the property exists and can be set.
At line:1 char:1
+ $user.ProxyAddresses = ("SMTP:" + $UPN.UserPrincipalName),("SIP:" + $UPN.UserPri ...
+ CategoryInfo : InvalidOperation: (:) , RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
What am i missing? Should i use a ForEach Loop?
Thanks in advance,