Reputation: 21
I have a .csv File looking like that:
"UserName" , "GroupName"
"t123","G-Q-TAT"
"t124","G-Q-ABC"
"t234","G-Q-ABD"
I want in Powershell creating an addionional column containing the SID.
So it should look like that:
"UserName" , "GroupName" , "SID"
"t123","G-Q-TAT","S-1-5-21-2079806555-1600217444-939750222-15100"
"t124","G-Q-ABC","S-1-5-21-2079806555-1600217444-939750222-15101"
"t234","G-Q-ABD","S-1-5-21-2079806555-1600217444-939750222-15102"
I tried the following:
Import-Module ActiveDirectory
Import-Csv c:\users.csv|foreach{
get-aduser $_.UserName -properties objectsid|select samaccountname, groupname, objectsid
}|export-csv c:\output.csv -NoTypeInformation
Everything works fine, except the groupname is not given out anymore. What did I wrong? Thank you a lot for your answers.
Upvotes: 1
Views: 666
Reputation: 21
Meanwhile I found the solution:
Import-Module ActiveDirectory
Import-Csv C:\users.csv|foreach{
$gruppe = $item.GroupName
get-aduser $_.UserName -properties objectsid , samaccountname |select samaccountname, objectsid , @{l="GroupName";e={$item.GroupName}}
}|export-csv "C:\output.csv" -NoTypeInformation
Upvotes: 1