cawasaki
asked on
powershell script to export all group that the distribution list are member
hello,
i have a csv file with 100 distribution list
i need a script to export for every distribution list the active directory group that this distribution group is member
the output file can be like this:
nameof_distributionlist,me mber1,memb er2....
thanks for help
i have a csv file with 100 distribution list
i need a script to export for every distribution list the active directory group that this distribution group is member
the output file can be like this:
nameof_distributionlist,me
thanks for help
ASKER
hello,
i need to delete 100 distribution list, and before this, i need to now in what group this ditribution list is member.
i need to delete 100 distribution list, and before this, i need to now in what group this ditribution list is member.
ASKER
hello,
this command work for me but i need the script to do it for 100 group and get the output csv:
dsget group "CN=GROUP1,OU=Groups,DC=co ntoso,DC=c om" -memberof
this command work for me but i need the script to do it for 100 group and get the output csv:
dsget group "CN=GROUP1,OU=Groups,DC=co
$GroupList = Get-Content C:\Grouplist.txt
$ExportFile = C:\Output.csv
foreach($grp in $GroupList){
$adgrp = Get-ADGroup $grp -Properties *
$grp
$adgrp.members| select @{name='GroupName';Expression={$adgrp.name}},@{name='MemberDN';Expression={$_}}
} Export-Csv $ExportFile -NoTypeInformation
I think this should do it for you.
ASKER
hello,
this script list the member on this group and not memberof
this script list the member on this group and not memberof
I can't test this right now but you can try this:
$GroupList = Get-Content C:\Grouplist.txt
$ExportFile = C:\Output.csv
foreach($grp in $GroupList){
$adgrp = Get-ADGroup $grp -Properties *
$grp
$adgrp.memberof| select @{name='GroupName';Express ion={$adgr p.name}},@ {name='Mem berDN';Exp ression={$ _}}
} Export-Csv $ExportFile -NoTypeInformation
$GroupList = Get-Content C:\Grouplist.txt
$ExportFile = C:\Output.csv
foreach($grp in $GroupList){
$adgrp = Get-ADGroup $grp -Properties *
$grp
$adgrp.memberof| select @{name='GroupName';Express
} Export-Csv $ExportFile -NoTypeInformation
ASKER
hello,
now its good but it not export the result on file :
now its good but it not export the result on file :
[PS] D:\script\group>.\group.ps1
group1
GroupName MemberDN
--------- --------
group1 CN=GP1,OU=Groups,OU=...
group1 CN=GP2,OU=Groups,OU=...
group1 CN=GP3,OU=Groups,OU=...
cmdlet Export-Csv at command pipeline position 1
Supply values for the following parameters:
InputObject:
ASKER
hello
any help plz?
any help plz?
Sorry doing this from my phone. Missed the pipe. This should do it.
$GroupList = Get-Content C:\Grouplist.txt
$ExportFile = C:\Output.csv
foreach($grp in $GroupList){
$adgrp = Get-ADGroup $grp -Properties *
$grp
$adgrp.memberof| select @{name='GroupName';Express ion={$adgr p.name}},@ {name='Mem berDN';Exp ression={$ _}}
} | Export-Csv $ExportFile -NoTypeInformation
$GroupList = Get-Content C:\Grouplist.txt
$ExportFile = C:\Output.csv
foreach($grp in $GroupList){
$adgrp = Get-ADGroup $grp -Properties *
$grp
$adgrp.memberof| select @{name='GroupName';Express
} | Export-Csv $ExportFile -NoTypeInformation
ASKER
hello
other error now:
other error now:
[PS] D:\script\group>.\group.ps1
At D:\script\group\group.ps1:8 char:7
+ } | Export-Csv $ExportFile -NoTypeInformation
+ ~
An empty pipe element is not allowed.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : EmptyPipeElement
Sorry no time for testing. Try this:
$GroupList = Get-Content C:\Grouplist.txt
$ExportFile = C:\Output.csv
$output = foreach($grp in $GroupList){
$adgrp = Get-ADGroup $grp -Properties *
$adgrp.memberof| select @{name='GroupName';Expression={$adgrp.name}},@{name='MemberDN';Expression={$_}}
}
$output| Export-Csv $ExportFile -NoTypeInformation
ASKER
its work now,
its is possible to get on output filer the group member email adress?
thanks
its is possible to get on output filer the group member email adress?
thanks
ASKER
hello
any help plz?
any help plz?
This will add the email address property to the output:
Let me know if that's what you're looking for.
$GroupList = Get-Content C:\Grouplist.txt
$ExportFile = C:\Output.csv
$output = foreach($grp in $GroupList){
$adgrp = Get-ADGroup $grp -Properties *
$adgrp.memberof| select @{name='GroupName';Expression={$adgrp.name}},@{name='Email';Expression={$adgrp.mail},@{name='MemberOfDN';Expression={$_}}
}
$output| Export-Csv $ExportFile -NoTypeInformation
Let me know if that's what you're looking for.
ASKER
hello,
error on the script:
error on the script:
[PS] D:\script\group>.\group.ps1
At D:\script\group\group.ps1:4 char:38
+ $output = foreach($grp in $GroupList){
+ ~
Missing closing '}' in statement block.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : MissingEndCurlyBrace
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This doesn't make sense to me: