Newb Question re ForEach
insert n00b qualifier here...
trying dump membership of groups in ou.
so know creates sorted csv of group names in specified ou:
get-adgroup -filter * -searchbase '<dn ou of interest>' | select-object -property name | sort-object -property name | export-csv -path <path export csv>
and know give me formatted list of members of group:
get-adgroupmember -id $groups | select-object -property name | export-csv <path final csv>
so seems following should glue 2 to:
get-adgroup -filter * -searchbase 'ou=ou of interest,ou=root ou,dc=sub-domain,dc=domain,dc=tld' | select-object -property name | sort-object -property name | export-csv -path <path export csv>
import-csv <path export csv>
foreach-object{
get-adgroupmember -identity $_.name}|
select-object -property name | export-csv <path final csv>
sadly i'm still passing nothing identity parameter of get-adgroupmember:
get-adgroupmember : cannot validate argument on parameter 'identity'. argument null or empty. provide argument not null or empty, , try the
command again.
@ line:4 char:37
+ get-adgroupmember -identity $_.name}|
+ ~~~~~~
+ categoryinfo : invaliddata: (:) [get-adgroupmember], parameterbindingvalidationexception
+ fullyqualifiederrorid : parameterargumentvalidationerror,microsoft.activedirectory.management.commands.getadgroupmember
the source csv looks this:
name
groupname1
groupname2
groupname3
etc.
so yeah - i'm pretty sure should doing regularly in scripts if point out glaring error i've made here i'd obliged.
tia , that,
m-
hi michael,
i find it's easiest create custom objects when doing this. here's example can play with:
get-adgroup -filter * -searchbase 'ou=security groups,dc=domain,dc=com' | foreach-object { $props = @{ groupname = $_.name members = (get-adgroupmember -identity $_.name -recursive | sort name | select -expandproperty name) -join ', ' } new-object psobject -property $props } | select groupname,members | sort groupname | export-csv .\grouplist.csv -notypeinformation
Windows Server > Windows PowerShell
Comments
Post a Comment