我试图逐行将文本文件读入get-adgroup cmdlet,以便从txt文件中获得用户是组成员的列表。
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:无法将参数“Identity”绑定到目标。异常设置"Identity":“无法验证参数上的参数:'Identity‘。参数为空或空。请提供一个非空或空的参数,然后再试一次命令。”行:6字符:15+ {get-adgroup <<<< $item -properties *x选择samaccountname,成员}+ CategoryInfo : WriteError:(:) Get-ADGroup,ParameterBindingException + FullyQualifiedErrorId : ParameterBindingFailed,CategoryInfo
但是,当我循环遍历数组时,它返回到组名ok。
Clear-Host;
$groups = "./desktop/groups.txt"
$arrayofgroups = Get-Content $groups
foreach ($item in $arrayofgroups ) {
$item
}我已经证实了,如果您只运行下面的代码,它就能正常工作。
get-adgroup "group 1" -properties * | select samaccountname, members我是新来的PowerShell的VBscript,不知道为什么这不工作,有什么想法吗?
发布于 2014-01-15 16:50:02
在包含PSBreakpoint命令的行中,在foreach循环中设置一个foreach。在调试器中,键入$Item以检查$Item变量的值。还可以尝试输入$Item.Length来查看它到底有多少个字符长。确保源文件中没有任何额外的、不必要的空格。
https://stackoverflow.com/questions/21143141
复制相似问题