superdave1984
Repeat Offender
- Messages
- 1,986
- Location
- KY
I will admit to having limited knowledge of powershell. What I need is to be able to take a list of users (user_lookup.csv) and export each into a csv that shows all groups each user is a member of. My script is this:
Import-Module activedirectory
$ADUsers = Import-csv C:\test\CSV\user_lookup.csv
$ErrorActionPreference= 'silentlycontinue'
#Loop through each row containing user details in the CSV file
$output = foreach ($User in $ADUsers)
{
#Read user data from each field in each row and assign the data to a
variable as below
$Username = $User.username
Get-ADPrincipalGroupMembership $Username | select name
}
$output | Export-Csv -NoType -Path 'C:\test\data\user_lookup_data.csv'
So I have the list of user names in the csv file and it imports correctly. My issue is it generates a csv with all the groups, but does not separate into the different users. It is one long list. What changes do I need to make for this? It can either be a single csv with each user in a different column or a separate csv for each user. Also, the usernames need to show the actual name rather than the AD account name.Powershell is the only option available.
Import-Module activedirectory
$ADUsers = Import-csv C:\test\CSV\user_lookup.csv
$ErrorActionPreference= 'silentlycontinue'
#Loop through each row containing user details in the CSV file
$output = foreach ($User in $ADUsers)
{
#Read user data from each field in each row and assign the data to a
variable as below
$Username = $User.username
Get-ADPrincipalGroupMembership $Username | select name
}
$output | Export-Csv -NoType -Path 'C:\test\data\user_lookup_data.csv'
So I have the list of user names in the csv file and it imports correctly. My issue is it generates a csv with all the groups, but does not separate into the different users. It is one long list. What changes do I need to make for this? It can either be a single csv with each user in a different column or a separate csv for each user. Also, the usernames need to show the actual name rather than the AD account name.Powershell is the only option available.
Last edited: