积极答复者
Powershell get-adgroup问题

问题
-
目的:导出Folder下的所有group及group成员
OU结构:Group->Folder
代码如下:
$grouplist=get-adgroup -filter * -searchbase "ou=Folder,ou=Group,dc=abchf,dc=abcservices;dc=com";
Foreach($group in $grouplist)
{
$expath=$group.name+".csv";
$gmember=Get-adgroupmember -identity $group.name |select name,objectclass ;
$gmember|export-csv -path $expath;
}错误提示:
get-adgroup : The supplied distinguishedName must belong to one of the following partition(s):
'CN=Configuration,DC=abcservices,DC=com , CN=Schema,CN=Configuration,DC=abcservices,DC=com ,
DC=abchf,DC=abcservices,DC=com , DC=ForestDnsZones,DC=abcservices,DC=com ,
DC=DomainDnsZones,DC=abchf,DC=abcservices,DC=com'.
At C:\temp\List\groupmem.ps1:1 char:12
+ $grouplist=get-adgroup -filter * -searchbase "ou=Folder,ou=Group,dc=abchf,dc=abc ...但是单独使用get-adgroup -filter * -searchbase "ou=Folder,ou=Group,dc=abchf,dc=abcservices;dc=com";
是可以的!
路可以歪着走,但是方向一定要是对的~!
- 已编辑 还在路上 2016年6月27日 5:14
答案
-
你好,
powershell脚本在2.0和4.0上运行时是有一些不同。为了让该脚本能在powershell 2.0上运行,我们需要import system modules,测试一下导入模块后是否可以正确运行了。(另外,确保你是用Admin账号在操作)
Best Regards,
Anne
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.
- 已编辑 Anne HeMicrosoft contingent staff, Moderator 2016年6月29日 8:19
- 已建议为答案 Anne HeMicrosoft contingent staff, Moderator 2016年6月30日 5:52
- 已标记为答案 Anne HeMicrosoft contingent staff, Moderator 2016年7月5日 8:49
全部回复
-
现在这个已经可以在windows server 2012上运行但是在Windows server 2008 R2 SP1上还是不行。
2012上的powershell版本是4.0,2008上的powershell是2.0
提示错误是:
PS C:\Windows\system32> &"d:\logs\list\group.ps1"
Export-Csv : Cannot bind argument to parameter 'InputObject' because it is null
.
At D:\logs\list\group.ps1:6 char:20
+ $gmember|export-csv <<<< -path $expath;
+ CategoryInfo : InvalidData: (:) [Export-Csv], ParameterBindingV
alidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,M
icrosoft.PowerShell.Commands.ExportCsvCommand
Export-Csv : Cannot bind argument to parameter 'InputObject' because it is null路可以歪着走,但是方向一定要是对的~!
-
你好,
powershell脚本在2.0和4.0上运行时是有一些不同。为了让该脚本能在powershell 2.0上运行,我们需要import system modules,测试一下导入模块后是否可以正确运行了。(另外,确保你是用Admin账号在操作)
Best Regards,
Anne
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.
- 已编辑 Anne HeMicrosoft contingent staff, Moderator 2016年6月29日 8:19
- 已建议为答案 Anne HeMicrosoft contingent staff, Moderator 2016年6月30日 5:52
- 已标记为答案 Anne HeMicrosoft contingent staff, Moderator 2016年7月5日 8:49