我是第一次使用 PowerShell。我正在尝试使用一个脚本,让我从组中所有人的 Active Directory 中获取一些属性。下面是我找到并尝试使用的脚本,但它给了我一个错误。\
我的 OU.csv 有内容:
Dn "OU=something,OU=something1,DC=something2,DC=com"
UserInfo.txt 为空
搜索AD_UserInfo:
# Search Active Directory and Get User Information
#
# www.sivarajan.com
#
clear
$UserInfoFile = New-Item -type file -force "C:\Scripts\UserInfo.txt"
"samaccountname`tgivenname`tSN" | Out-File $UserInfoFile -encoding ASCII
Import-CSV "C:\Scripts\OU.csv" | ForEach-Object {
$dn = $_.dn
$ObjFilter = "(&(objectCategory=User)(objectCategory=Person))"
$objSearch = New-Object System.DirectoryServices.DirectorySearcher
$objSearch.PageSize = 15000
$objSearch.Filter = $ObjFilter
$objSearch.SearchRoot = "LDAP://$dn"
$AllObj = $objSearch.FindAll()
foreach ($Obj in $AllObj)
{ $objItemS = $Obj.Properties
$Ssamaccountname = $objItemS.samaccountname
$SsamaccountnameGN = $objItemS.givenname
$SsamaccountnameSN = $objItemS.sn
"$Ssamaccountname`t$SsamaccountnameGN`t$SsamaccountnameSN" | Out-File $UserInfoFile -encoding ASCII -append
}
错误:
Missing closing '}' in statement block.
At C:\Path\SearchAD_UserInfo
+ } <<<<
+ CategoryInfo : ParserError: (CloseBra
+ FullyQualifiedErrorId : MissingEndCurlyBrace