-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-ADUserGroupsPrimary.ps1
More file actions
17 lines (17 loc) · 977 Bytes
/
Get-ADUserGroupsPrimary.ps1
File metadata and controls
17 lines (17 loc) · 977 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Do{
import-module activedirectory
$output = Read-Host -Prompt 'Output to screen or to file (s or f)?'
$domain = Read-Host -Prompt 'What domain is the user in?'
$dcserver = Get-ADDomainController -Discover -Domain $domain
$user = Read-Host -Prompt 'Enter the username of the individual you want group membership details for'
$outputpath = "C:\Users\$env:UserName\Downloads\ADUserPrimaryGroups-$domain-$user-$([DateTime]::Now.ToString("yyyyMMdd-HHmmss")).txt"
If ($output -like "s*") {
Get-ADPrincipalGroupMembership -Identity $user -Server $dcserver | Get-ADGroup -Properties * | Select name,GroupCategory
}
else {
Get-ADPrincipalGroupMembership -Identity $user -Server $dcserver | Get-ADGroup -Properties * | Select name,GroupCategory | Out-File -filepath $outputpath
Write-Output "Results written to: $outputpath"
}
$response = read-host "Would you like to search for another user (Y/N)?"
}
while ($response -like "Y*")