Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

script to populate ProxyAddresses and Mail attribute based on the UserPrincipalName

$
0
0

Hi,

 

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,


Viewing all articles
Browse latest Browse all 6937

Trending Articles