域内用户及计算机太多,但有要求需绑定用户的登录计算机。
注意:脚本请勿重复执行,不然就会在用户可登录的计算机中产生重复计算名。
注意:脚本请勿重复执行,不然就会在用户可登录的计算机中产生重复计算名。
1、windows2003安装.net2框架
2、 微软官方下载PowerShell:(找到适合系统的版本)
简体X86:http://www.microsoft.com/zh-cn/download/confirmation.aspx?id=15406
3、绑定脚本:(复制代码存为test01.ps1)
脚本地址:http://gallery.technet.microsoft.com/scriptcenter/852fe273-03ed-449f-8591-57b655cba82e
#
# 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
# 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
# 域名格式例:"LDAP://dc=test,dc=local"
$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()
}
4、名单对应表:(input.csv)
格式如下:(支持单用户绑定多计算机)
$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()
}
4、名单对应表:(input.csv)
格式如下:(支持单用户绑定多计算机)
5、将test01.ps1与input.csv放置至某文件夹内C:\Scripts。
6、运行PowerShell, 允许运行未签名脚本:(默认为禁用脚本)
进入C:\Scripts,并运行:
7、完美运行完成: