powershell - 根据Get-AdUser的结果设置AD用户的UPN

标签 powershell active-directory

我在AD中有一些用户将UPN地址设置为User@this.org。我想更改这些用户,以便他们的UPN看起来像User@that.com

我写了一条PS线来找到我这样的用户:

Get-ADUser -LDAPFilter "(&(objectCategory=person)(objectClass=user)(!userAccountControl:1.2.840.113556.1.4.803:=2)(userPrincipalName=*@this.org))" -SearchBase "OU=this,DC=that"  | Select SamAccountName

但是我该如何更新那些用户。我知道Set-AdUser命令,但是我不知道如何将Get-Aduser的结果输入到其中。

最佳答案

只需将其传送到Set-ADUser:

Get-ADUser -LDAPFilter "(&(objectCategory=person)(objectClass=user)(!userAccountControl:1.2.840.113556.1.4.803:=2)(userPrincipalName=*@this.org))" -SearchBase "OU=this,DC=that" | % {Set-ADUser $_ -UserPrincipalName "that"} 

请注意,在整个广告崩溃之前,请在测试期间使用-Whatif

说明:
%-foreach的别名
$_-等于foreach的每个对象(每个用户在Get-ADuser中找到)
-UserPrincipalName "that"-将给定用户的UPN设置为that

关于powershell - 根据Get-AdUser的结果设置AD用户的UPN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51671702/

相关文章:

hash - 将 Active Directory 密码哈希设置为 SHA1 值?

powershell - Powershell-将计算机添加到Active Directory中的安全组

powershell - token '&&' 在 vs 代码终端的这个版本中不是有效的语句分隔符

json - 如何使用 Powershell 将 JSON 对象保存到文件中?

powershell - Azure Devops IIS Web 应用程序管理失败并出现 powershell 错误

powershell - 是否可以使用 Powershell 在 Active Directory 中设置用户 memberOf 属性

python - 新的 Azure 订阅未与 azure python sdk 一起列出

powershell - 有没有更快的方法来获取从 powershell 中的特定目录开始的磁盘使用情况?

sql-server - Powershell 将 SQL Server 数据库恢复到新数据库

node.js - ldap查询获取组node.js中的所有用户