0

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

beatcracker
  • 6,714
  • 1
  • 18
  • 41
user3290171
  • 121
  • 1
  • 3
  • 19
  • Id probably use set-aduser -identity $xy -replace @{mailnickname = $xy}, what happens if you run this or your own code outside of the code you have provided above? Also does the mailnickname attribute exist? – Nick Eagle Oct 12 '15 at 17:31
  • It does exist under using LDAP display names. when you change it to use friendly names it does not appear in quest? It is underlined if that makes a difference? when I try and run your code in it it says I have insuffecient right when I definately do have the rights to change this. If I run it outside it still doesn't work, run the over code on it's own it still works :| Thanks in advance – user3290171 Oct 13 '15 at 09:18

2 Answers2

0

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}

Responding to your question below:

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.

Community
  • 1
  • 1
Nate
  • 802
  • 1
  • 8
  • 28
  • Or I imagine your existing code of `Set-QADUser -identity $xy -ObjectAttributes @{mailnickname = $xy}` could just be adjusted to `get-qaduser $xy | Set-QADUser -ObjectAttributes @{mailnickname = $xy}` but I don't use Quest. You could also just make it one line with `get-qaduser $xy | Set-QADUser -ObjectAttributes @{msExchVersion="44210883383015";mailnickname = $xy}` I bet. – Nate Oct 13 '15 at 15:39
  • Unfortuantely I can only use PS1, would this be why I am getting the issue? Is there anyway around it, I also have the Active Directory Module for windows Powershell. Perhaps a better way using this? Thanks – user3290171 Oct 13 '15 at 17:15
  • I updated my response to you. Try that script. Just copy the script and save it as a .ps1 and run that in PowerShell ISE so you can see the errors. Report the errors back to me. – Nate Oct 13 '15 at 21:15
  • I will try this when I am back to work on Monday. Thanks – user3290171 Oct 16 '15 at 09:32
  • @user3290171 You never told me if this helped you or not... `SadFace` – Nate Nov 11 '15 at 20:42
-1

The likely reason you're seeing this is because of the ARS 'Built-in Policy - Default E-mail Alias' Policy. You can verify that this is the case by checking the change history for the user object(s) you're trying to create/modify.

You'll see Property 'Alias (mailNickName)' is removed from the operation request as no Exchange tasks were requested.

Try setting the targetAddress attribute at the same time to avoid being dropped by this policy.

apocalysque
  • 332
  • 2
  • 6
  • 1
    You must remember that Stack Overflow is not a forum. Before your edit, your "answer" was not an answer, it was a *question*, hence somebody downvoted it. Even now, it's hard for me to tell if the answer actually answers the question posed by the original author - you'd do better to reword it so that it's clear you are trying to answer *that* question, not just yours. – Ajean Feb 04 '16 at 18:04
  • I'm sorry, I'm kind of new to this. I realize I should have posted a comment and not an answer. I'll edit it to make my answer more clear. – apocalysque Feb 04 '16 at 18:08