您必须使用 Quest 吗?这本机适用于 PS v3:
Get-ADUser $xy | Set-ADUser -Add @{mailNickname=$xy}
或者:
Get-ADUser $xy | Set-ADUser -Replace @{mailNickname=$xy}
在下面回答您的问题:
我假设您的意思是 PowerShell v1。我没用过PS v1。你是用 开始你的脚本Import-Module ActiveDirectory
吗?如果没有,您应该将其发布在行首。对于 Quest around here,脚本始终以 开头,Import-Module ActiveDirectory
下一行是Add-PSSnapIn Quest.ActiveRoles.ADManagement
. 这适用于 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}
看看这是否满足您的需求并回复我。请记住:在此示例中,您将变量 $XY 声明为用户在运行脚本时输入的任何内容。