Hey Folks,
I’ve been stumped on this one. I need to read a .csv and output the data into a format that our access review tool can use.
Here is an example of the data:
User,Role,Role Description
UserA,CAT,Meow Meow
UserA,General,General End User
UserA,Help,Helpdesk
UserA,ZZTOP,Self Service
UserA,Wizard,Support Role
UserB,CAT,Meow Meow
UserB,General,General End User
UserB,Help,Helpdesk
UserB,ZZTOP,Self Service
UserB,Wizard,Support Role
UserC,CAT,Meow Meow
UserC,General,General End User
UserC,Help,Helpdesk
UserC,ZZTOP,Self Service
UserC,Wizard,Support Role
UserD,CAT,Meow Meow
UserD,General,General End User
UserD,Help,Helpdesk
UserD,ZZTOP,Self Service
UserD,Wizard,Support Role
UserE,SECURITY1,Secure
UserE,SECURITY2,More Secure
UserE,EXEMPT,Exempts
UserE,General,General End User
UserE,ZZTOP,Self Service
The output needs to read:
CAT,Meow Meow,UserA,UserB,UserC,UserD
(Role, Role Description, User, User, User, etc)
Here is what I have so far, but a line is being outputted for each user. How could I adjust this to match what the output needs to be?
$Data = Import-Csv "C:\Data.csv" $UniqueRoles = Import-Csv "C:\Data.csv" | Select-Object Role | Sort-Object Role -Unique Foreach($R in $UniqueRoles){ ForEach ($D in $Data){ If ($R.Role -eq $D.Role){ $1 = $R.Role + "," + $D."Role Description" + ",$($D.User)" } } $1 | out-file "C:\report.txt" -Append }
Any help is greatly appreciated. Thanks!