PowerShell Get-ADUserGroupMembership

Sep 14th, 2010
#Get-ADUserGroupMembership
########################################################################
# This PoSh script will read input of AD Users from a text file-c:\ADUsers.tx  and output
# the respective user’s AD Group Membership in a .csv file -C:\UserGroup.csv.
# REQUIREMENTS:
# Quest Active Directory cmdLets must be installed on the machine that script will run from.
#Witten By: www.isaacoben.com
#Version: 1.2
#########################################################################
#Add QAD cmdlets
Add-PSSnapin Quest.ActiveRoles.ADManagement -ErrorAction SilentlyContinue
#Get User list from text file ADUser.txt
$ADUser = Get-Content “c:\ADUsers.txt”
#Count number of users on list
$ADUser_Count = $ADUser.Length
#Enumerate the number of users
$i = 0;
ForEach ($targetUser in $ADUser)
{
$Progress_bar = [int][Math]::Ceiling((($i / $ADUser_Count) * 100))
#Start Displaying Progress activity
Write-Progress -Activity “Retrieving AD Group Membership for $targetUser” -PercentComplete $Progress_bar -Status “$Progress_bar% Complete” -SecondsRemaining $Progress_bar
Sleep (1)
$Current_User = Get-QADUser $targetUser
$Current_User| Get-QADMemberOf |Select-Object $Current_User.Name, name|Out-File -FilePath ‘C:\UserGroup.csv’-Append
$i ++
}
Write-Progress -Activity “Retrieved All Users” -PercentComplete 100 -Status “Done – 100%”
Sleep (1)
Be Sociable, Share!