简体   繁体   English

Powershell设置Mailnickname属性

[英]Powershell setting Mailnickname attribute

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. 我有一些powershell代码,在创建用户后,该代码使用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? 您必须使用Quest吗? This works in PS v3 natively: 这可以在PS v3中正常运行:

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. 我假设您的意思是PowerShell v1。 I haven't used PS v1. 我没有使用PS v1。 Are you starting your script with Import-Module ActiveDirectory ? 您是否要使用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 . 对于此处的Quest,脚本始终以Import-Module ActiveDirectory开头,下一行是Add-PSSnapIn Quest.ActiveRoles.ADManagement This would work in PS v2: 这将在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. 请记住:在此示例中,您将变量$ XY声明为用户在运行脚本时输入的变量。

The likely reason you're seeing this is because of the ARS 'Built-in Policy - Default E-mail Alias' Policy. 您看到此问题的可能原因是由于ARS的“内置策略-默认电子邮件别名”策略。 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. 您会看到属性'Alias(mailNickName)'已从操作请求中删除,因为未请求任何Exchange任务。

Try setting the targetAddress attribute at the same time to avoid being dropped by this policy. 尝试同时设置targetAddress属性,以避免被该策略删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM