I have a bit of powershell code that after a user has been created the code assigns the account loads of attributes using Quest/AD. All the attributes assign except Mailnickname. Is there a reason for this / how can I fix it. Below is my code:
get-qaduser $xy | Add-QADProxyAddress -Address ("SMTP:"+$x) -verbose
get-qaduser $xy | Add-QADProxyAddress -Address ("SMTP:"+$xy+"@domainexample.mail.onmicrosoft.com") -verbose
get-qaduser $xy | Set-QADUser -ObjectAttributes @{msExchVersion="44210883383015"} -verbose
Set-QADUser -identity $xy -ObjectAttributes @{mailnickname = $xy}
Would anyone have any suggestions of what to / how to go about setting this.
Thanks in advance.
Steve
Do you have to use Quest? This works in PS v3 natively:
Get-ADUser $xy | Set-ADUser -Add @{mailNickname=$xy}
Or:
Get-ADUser $xy | Set-ADUser -Replace @{mailNickname=$xy}
I assume you mean PowerShell v1. I haven't used PS v1. Are you starting your script with Import-Module ActiveDirectory
? If not, you should post that at the top of your line. For Quest around here the script always starts with Import-Module ActiveDirectory
and the next line is Add-PSSnapIn Quest.ActiveRoles.ADManagement
. This would work in PS v2:
Import-Module ActiveDirectory
Add-PSSnapIn Quest.ActiveRoles.ADManagement
#This line lets you just type the user you want to modify
$XY = Read-Host "Input User ID"
#This is your code you said works
get-qaduser $xy | Add-QADProxyAddress -Address ("SMTP:"+$x) -verbose
get-qaduser $xy | Add-QADProxyAddress -Address ("SMTP:"+$xy+"@domainexample.mail.onmicrosoft.com") -verbose
get-qaduser $xy | Set-QADUser -ObjectAttributes @{msExchVersion="44210883383015"} -verbose
#This should add the mailNickname property through standard PS
Get-ADUser $XY | Set-ADUser -Add @{mailNickname = $XY}
See if that does what you need and get back to me. Remember: in this example you're declaring the variable $XY to be whatever the user inputs when running the script.