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

2023-09-08 12:26:39 作者:脑残也是残疾的一种

说我有用户和他们的physicalDeliveryOfficeName属性,称为Office公元设置为纽约,和其他人说芝加哥。

Say I have users and their physicalDeliveryOfficeName attribute, called Office in AD is set to New York, and others say Chicago.

我想设置一个脚本,将通过所有的用户环路。

I want to setup a script that will loop through all users.

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

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

I can't seem to find out where to start.. any pointers?

推荐答案

假设你已经PowerShell的2.0版,您可以使用内置Active Directory模块的,特别是,所述的获取-ADUser便有的命令,随后设置-ADUser便有,是这样的:

Assuming you have PowerShell v2.0, you can use the built-in Active Directory module, in particular, the Get-ADUser command followed by Set-ADUser, something like:

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

都可以按上述或通过 Get-Help的链接可用属性的完整列表和一些例子 cmdlet的。

The full list of available attributes and some examples are available by following the links above or via the Get-Help cmdlet.

如果你不是在PowerShell的2.0版和不能升级出于某种原因,你可以使用的。NET的System.DirectoryServices 命名空间以及相关的类,在这里你应该能够合理地紧跟在MSDN的例子,的如此更新和这个例子搜索。此外,#1有无数的例子,虽然this 之一看上去就快速审查特别有前途的。

If you're not on PowerShell v2.0 and can't upgrade for some reason, you can use the .NET System.DirectoryServices namespace and associated classes, where you should be able to follow reasonably closely the MSDN examples, e.g. this for updating and this example for searching. Additionally, Stackoverflow has numerous examples, though this one looks particularly promising on a quick review.

另外,我错过了href="http://technet.microsoft.com/en-us/library/ff730967.aspx" rel="nofollow">使用PowerShell和System.DirectoryServices中搜索微软例如