我的.csv文件看起来像这样:
"UserName" , "GroupName"
"t123","G-Q-TAT"
"t124","G-Q-ABC"
"t234","G-Q-ABD"
我想在Powershell中创建一个包含SID的附加列。
所以看起来应该是这样的:
"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"
我尝试了以下内容:
Import-Module ActiveDirectory
Import-Csv c:\users.csv|foreach{
get-aduser $_.UserName -properties objectsid|select samaccountname, groupname, objectsid
}|export-csv c:\output.csv -NoTypeInformation
一切正常,但组名不再发出。我错了什么? 非常感谢你的回答。
答案 0 :(得分:1)
同时我找到了解决方案:
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