• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1516
  • Last Modified:

script to populate ProxyAddresses and Mail attribute based on the UserPrincipalName

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,
0
bmdgi
Asked:
bmdgi
  • 3
  • 2
1 Solution
 
footechCommented:
Do the users currently have anything set for the proxyAddresses attribute?  If so, does it matter if that information is overwritten?

If you can use the Exchange cmdles, it may be better to do so, but I wouldn't be able to provide guidance there.
0
 
footechCommented:
Not caring about overwriting anything, you could use the following (and I guess you want to set the Mail attribute as well):
Get-ADUser -Filter * -Properties UserPrincipalName | ForEach `
{
    Set-ADUser $_.samaccountname -EmailAddress "$($_.UserPrincipalName)" -replace @{proxyAddresses = "SMTP:$($_.UserPrincipalName)","SIP:$($_.UserPrincipalName)"}
}

Open in new window

0
 
bmdgiAuthor Commented:
used the following:

Get-ADUser -Filter * -Properties mail,ProxyAddresses | Foreach {
  $_.ProxyAddresses = ("SMTP:" + $_.UserPrincipalName),("SIP:" + $_.UserPrincipalName)
 $_.mail = $_.UserPrincipalName
 Set-ADUser -instance $_
}
0
 
footechCommented:
It's usual with PowerShell for there to be more than one way to accomplish the same thing.  I know what I posted works, as it is tested.  Glad you found your own method, though I'm not sure why you didn't use my solution (though it does seem you used ideas from my code, in which case an assist is appropriate).
0
 
bmdgiAuthor Commented:
found answer
0

Featured Post

Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now