最近在绑定计算机AD账户和计算机名的时候,发现用户账户过多,手动绑定手都抽筋了。所以找朋友要了个脚本,朋友只在2003上面执行过,不知道2008上面执行是否有问题,所以就测试了一把。完美执行;

   脚本地址:http://gallery.technet.microsoft.com/scriptcenter/852fe273-03ed-449f-8591-57b655cba82e

1.复制一下代码保存为xx.ps1

#
# www.sivarajan.com
# blogs.sivarajan.com
# You can use this PowerShell script to update or modify the Log On To (userWorkstations) attribute in Active Directory.
# Version 1.1
# Author - Santhosh Sivarajan
#
Clear
Import-CSV input.csv| % {
$UserN = $_.UserName
$ComputerN = $_.ComputerName
$ObjFilter = "(&(objectCategory=person)(objectCategory=User)(samaccountname=$UserN))"
$objSearch = New-Object System.DirectoryServices.DirectorySearcher
$objSearch.PageSize = 15000
$objSearch.Filter = $ObjFilter
$objSearch.SearchRoot = "LDAP://dc= 域名,dc= 域名后缀"
$AllObj = $objSearch.findOne()
$user = [ADSI] $AllObj.path
$ErrorActionPreference = "silentlycontinue"
If (($user.get("userWorkstations")) -ne $null)
{$ComputerN = $user.get("userWorkstations")+","+ $ComputerN}
Write-host -NoNewLine "Updating $UserN Properties ..."
$user.psbase.invokeSet("userWorkstations",$ComputerN)
Write-host "Done!"
$user.setinfo()
}

  2.创建Input.csv名单

3.把上面的脚本和下面的Input.csv保存到C盘C:\Scripts

4.运行PowerShell(第一运行的时候默认禁用脚本,需要打开)

5.进入C盘根目录

6.进入Scripts目录执行脚本;

7.完美执行

8.我们查看绑定的情况,由于脚本执行了多次,所以会出现重复的计算机名;