-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathADGroups_to_txt.ps1
More file actions
32 lines (23 loc) · 1.13 KB
/
ADGroups_to_txt.ps1
File metadata and controls
32 lines (23 loc) · 1.13 KB
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
Import-Module ActiveDirectory
Function Get-Folder($initialDirectory) {
[void] [System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
$FolderBrowserDialog = New-Object System.Windows.Forms.FolderBrowserDialog
$FolderBrowserDialog.RootFolder = 'MyComputer'
if ($initialDirectory) { $FolderBrowserDialog.SelectedPath = $initialDirectory }
[void] $FolderBrowserDialog.ShowDialog()
return $FolderBrowserDialog.SelectedPath
}
Write-Host "This creates a txt file for each AD group and its users"
Write-Host "As this gets information about users it may generate errors when it comes across groups that contain computers"
Write-Host "Please select an ouput folder"
$output_folder = Get-Folder
Write-Host "This may take awhile"
$groups = (Get-AdGroup -filter * | Where-Object { $_.name -like "**" } | Select-Object name -ExpandProperty name)
ForEach ($g in $groups) {
$path = $output_folder + "\" + $g.Name + ".txt"
$results = (Get-ADGroupMember -Identity $g.Name -Recursive | Get-ADUser -Properties displayname, name)
ForEach ($r in $results) {
$r.displayname | Out-File $path -Append
}
}
Write-Host "Done!"