我正在嘗試逐行讀取文本文件到get-adgroup cmdlet中,以獲取哪些用戶是來自txt文件的組成員的列表Powershell Get-ADGroup:無法綁定參數'Identity'
Clear-Host;
$groups = "./desktop/groups.txt"
$arrayofgroups = Get-Content $groups
foreach ($item in $arrayofgroups) {
Get-ADGroup $item -properties * | select samaccountname, members
}
文本文件看起來像這樣:
"group 1"
"group 2"
下面的代碼返回:
Get-ADGroup : Cannot bind parameter 'Identity' to the target. Exception setting "Identity": "Cannot validate argument on parameter: 'Identity'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again." At line:6 char:15 + {get-adgroup <<<< $item -properties * | select samaccountname, members} + CategoryInfo : WriteError: (:) [Get-ADGroup], ParameterBindingException + FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.ActiveDirectory.Management.Commands.GetADGroup
然而,當I L通過陣列面向對象,它返回到組名確定
Clear-Host;
$groups = "./desktop/groups.txt"
$arrayofgroups = Get-Content $groups
foreach ($item in $arrayofgroups) {
$item
}
我已經verfied,如果你只需要運行下面的正常工作。
get-adgroup "group 1" -properties * | select samaccountname, members
我是新來的PowerShell從VBScript,和我不知道爲什麼,這是不行的,有什麼想法?
$ arrayofgroups.count返回什麼?如果這些名稱在文件中引用,則應刪除引號。 – mjolinor