forked from RyanC92/Powershell-Repository
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReport-ADGroupMembers_2019.ps1
40 lines (25 loc) · 1.12 KB
/
Report-ADGroupMembers_2019.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Function Get-FileName($InitialDirectory)
{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.Dereferencelinks = $False
$OpenFileDialog.initialDirectory = $initialDirectory
#$OpenFileDialog.filter = "CSV (*.csv) | *.csv"
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.FileName
}
$RoleList = Get-FileName
#$AllRoles = @()
$RL = Import-csv $RoleList
ForEach($User in $RL){
Get-Adgroupmember -Identity $User.Role | select @{Expression = {$User.Role}; Label = "Role"},Name,SamAccountName | Export-CSV C:\CSV\MemberCount-$([DateTime]::Now.ToString("MM-dd-yyyy-hh.mm.ss")).csv -append -NoTypeinformation
}
<#
$EndUsers = Get-AdgroupMember -Identity $($User.Role) | Select Name, SamAccountName
$AllRoles += [pscustomobject]@{
"Role" = $User.Role
"User" = $($EndUsers.Name)
"Username" = $($Endusers.SamAccountName)
}
$AllRoles #| Export-CSV C:\CSV\MemberCount-$([DateTime]::Now.ToString("MM-dd-yyyy-hh.mm.ss")).csv -append -NoTypeinformation
#>