我们正在致力于更新AD中的scriptPath属性。我们正在更新小组的员工(一次约100-200人)。为此我创建了以下脚本。Powershell脚本中的不明原因数字输出
$newScript = "foo.vbs"
# Load Employee List
$employeeList = Get-Content "NAM_logon_EmployeeList.txt"
$objDomain = New-Object System.DirectoryServices.DirectoryEntry("LDAP://OU=Users,DC=foobar,DC=com")
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.PageSize = 100
$objSearcher.SearchScope = "Subtree"
$colProplist = "scriptPath", "distinguishedName", "cn"
# Loop through Employee List and update the script value
ForEach ($employee In $employeeList) {
$objSearcher.Filter = "(&(objectCategory=person)(objectClass=user)(mail=$employee))"
Foreach ($colProp in $colPropList) {
$objSearcher.PropertiesToLoad.Add($colProp)
}
$colResults = $objSearcher.FindAll()
ForEach ($user In $colResults) {
$ntuser = $user.Properties.Item("distinguishedName")
$myUser = $user.Properties.Item("cn")
Script to Pushout the change
$objUser = [ADSI]"LDAP://$($ntuser)"
$objUser.put("scriptPath", $newScript)
$objUser.SetInfo()
echo "Script Added for $($myUser)"
}
}
该脚本工作正常,但第18行:
$objSearcher.PropertiesToLoad.Add($colProp)
输出数字到PowerShell窗口。每个对象和属性添加一个数字。
0
1
2
Script Added for Smith, John
4
5
6
Script Added for Doe, Jane
等
我不知道为什么它这样做。有人有主意吗?
这是一个更透彻的解释比我提供什么,而只是发表评论'$空='或'[空]'是最好的方法以处理摆脱不必要的输出。 '| Out-Null'明显变慢。 – 2014-09-30 16:57:25
你是对的,它是。就我个人而言,我更喜欢它的读法,我从来没有遇到性能问题,所以我只是坚持下去。 – Travis 2014-09-30 16:59:17
谢谢你们俩。我尝试了两种方式,并没有注意到性能的差异。但我仍然会使用'$ null ='方法。 – Shawrich 2014-09-30 18:46:43