繁体   English   中英

通过 PowerShell 修改 AD 中的属性(无任务)

[英]Modify attributes in AD via PowerShell (no Quest)

假设我有用户和他们的physicalDeliveryOfficeName 属性,AD 中的Office 设置为New York,其他人说Chicago。

我想设置一个循环遍历所有用户的脚本。

If physicalDeliveryOfficeName = Chicago  
Set address properties   
Street: 8888 Chicago Lane  
City: Chicago  
State: IL  
Zip: 60066  
Country: United States

else if physicalDeliveryOfficeName = New York  
Set address properties  
Street: 9999 New York Lane
City: New York
State: NY
Zip: 11111
Country: United States

我似乎无法找到从哪里开始..任何指针?

假设您有 PowerShell v2.0,您可以使用内置的 Active Directory 模块,特别是Get-ADUser命令后跟Set-ADUser ,例如:

Get-ADUser -Filter {Office -eq "Chicago"} | Set-ADUser -StreetAddress "8888 Chicago Lane City" -City "Chicago" -State "IL" -PostalCode "60066" -Country "US"

可以通过上面的链接或通过Get-Help cmdlet 获得可用属性的完整列表和一些示例。

如果您不在 PowerShell v2.0 上并且由于某种原因无法升级,您可以使用.NET System.DirectoryServices命名空间和相关类,您应该能够合理地密切关注 MSDN 示例,例如用于更新这个例子用于搜索 此外,Stackoverflow 有很多例子,尽管这个例子看起来特别有前途。

另外,我错过了使用 PowerShell 和 System.DirectoryServices 进行搜索的 Microsoft 示例

我调整了上述内容以添加/更改从一个位置移动到另一个位置的员工的地址信息。 在下面的示例中,我当然更改了 John Doe 的地址。 但这是一个单行 powershell 命令行,非常适合尚未学习脚本的人:

get-aduser -filter {SamAccountName -eq "jdoe"} | Set-ADUser -Office "New York" -StreetAddress "123 N Main St" -city "New York" -State "NY" -PostalCode "10044" -Country "US"

暂无
暂无

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

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