Quantcast
Channel: PowerShell
Viewing all articles
Browse latest Browse all 15370

Script to list all active users and their group membership in a domain

$
0
0

I have been trying to modify the script created by Martin Pugh to list all active user and the groups that they are members of. Ultimately I would like to export the results to a .csv. I have been having problem modifying this script to get all the active users. I am a scripting novice and with a little work can usually get a script to do what I want but this one has me stumped.

Thanks in advance for your help.

Param (
[Parameter(Mandatory=$true,ValueFromPipeLine=$true)]
[Alias("ID","Users","Name")]
[string[]]$User
)
Begin {
Try { Import-Module ActiveDirectory -ErrorAction Stop }
Catch { Write-Host "Unable to load Active Directory module, is RSAT installed?"; Break }
}

Process {
ForEach ($U in $User)
#Get-ADUser -Filter {Enabled -eq "True"}
{ $UN = Get-ADUser $U -Properties MemberOf
$Groups = ForEach ($Group in ($UN.MemberOf))
{ (Get-ADGroup $Group).Name
}
$Groups = $Groups | Sort
ForEach ($Group in $Groups)
{ New-Object PSObject -Property @{
Name = $UN.Name
Group = $Group
}
}
}
}


Viewing all articles
Browse latest Browse all 15370

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>