Skip to content

Commit 33fc0f7

Browse files
committed
Add Get-SecurityGroupMembers.ps1
Add README.md
1 parent 48182fb commit 33fc0f7

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<#
2+
.SYNOPSIS
3+
Export Security Group Membership to CSV
4+
5+
.NOTES
6+
NAME: Get-SecurityGroupMembers.ps1
7+
VERSION: 1.0
8+
AUTHOR: Daniel Tsekhanskiy
9+
LASTEDIT: 2/7/2017
10+
#>
11+
12+
13+
$users = import-csv c:\temp\grouplist.csv"
14+
$output = ForEach ($item in $users)
15+
16+
{
17+
18+
# I like to assign each property value to a simpler named variable, but it’s not necessary
19+
20+
$Group = $item.(Group")
21+
22+
#Uses Get-ADGroupMember function to go through all rows under the column titled "Group" in the CSV and outputs the name
23+
24+
write-output $Group
25+
write-output "--------"
26+
<#
27+
write-output $(Get-ADGroupMember -Identity $Group |
28+
Where-Object { $_.objectClass -eq 'group' }) |
29+
select name
30+
31+
Get-ADGroupMember -Identity $Group |
32+
Where-Object { $_.objectClass -eq 'user' } |
33+
Get-ADUser -Properties employeeID |
34+
select name,employeeID | ConvertTo-Csv -NoTypeInformation |
35+
% { $_ -replace '"', ""}
36+
#>
37+
38+
39+
$results = Get-ADGroupMember -Identity $Group | select name,employeeID,objectClass,samaccountname
40+
41+
foreach ($result in $results){
42+
if ($result.objectClass -like 'group'){
43+
Write-Output $result.name
44+
}
45+
elseif ($result.objectClass -eq 'user'){
46+
$aduser = Get-ADUser -Identity $result.samaccountname -Properties employeeID
47+
Write-Output "$($result.name), $($aduser.employeeID)"
48+
}
49+
}
50+
Write-Output ""
51+
52+
53+
54+
55+
56+
} $output | out-file "C:\temp\Groupmembers.csv" -Append -fo -en ascii
57+
58+
<#
59+
$ACL_NAME = "ACL_PM_RO"
60+
$in_file = "C:\Temp\secgroups\input\$ACL_NAME.csv"
61+
$out_file = "C:\Temp\secgroups\output\$ACL_NAME-output.csv"
62+
63+
$out_data = @()
64+
65+
ForEach ($row in (Import-Csv $in_file)) {
66+
$user = $row.'user name'
67+
$out_data += Get-ADGroup -Filter "Name -eq '$user'" | select Name
68+
$out_data += Get-ADUser -Filter "Name -eq '$user'" -Properties employeeID | select Name,employeeID
69+
70+
}
71+
72+
$out_data | convertto-csv -NoTypeInformation # | % { $_ -replace '"' } | out-file $out_file -fo -en ascii
73+
#>

Get-SecurityGroupMembers/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Export Security Group Membership to CSV

0 commit comments

Comments
 (0)