如何使用powershell将csv中的sid更改为user? [英] How can I use powershell to change sid in csv to user?
本文介绍了如何使用powershell将csv中的sid更改为user?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这似乎基本,但无法找到或找出任何地方。
This seems basic however can't find or figure out anywhere.
我有一个要导入的.csv文件,将具有不同SID的用户列更改为对应的用户名,然后导出回.csv 。我知道如何找到SIDtoUser,但我不知道如何在.csv中的替换。
I have a .csv file that I would like to import, change the user column that has different SIDs to the user name that corresponds, then export back to the .csv. I know how to find the SIDtoUser, but I can't figure out how to do the replace in the .csv. Also some user columns are blank or have "admin" which I need to leave alone.
目前
ComputerName, TimeStamp, Message, User
hp8440, 8/30/2012, message1, admin
hp8440, 8/30/2012, message2
hp8440, 8/30/2012, message3, S-1-5-21...1105
hp8440, 8/30/2012, message4, S-1-5-21...1255
想阅读
ComputerName, TimeStamp, Message, User
hp8440, 8/30/2012, message1, admin
hp8440, 8/30/2012, message2
hp8440, 8/30/2012, message3, user1
hp8440, 8/30/2012, message4, user2
推荐答案
Import-Csv .\sid.csv | ForEach-Object{
if($_.User -and $_.User -ne 'admin')
{
# User is not empty and not admin
# perform translation and assign the results back to the User column
# then return the current object back to the pipeline
$_.User = (New-Object System.Security.Principal.SecurityIdentifier $_.User).Translate([System.Security.Principal.NTAccount]).Value
$_
}
else
{
# Ignore empty User or admin
# and return the current object back to the pipeline
$_
}
} | Export-Csv .\users.csv
这篇关于如何使用powershell将csv中的sid更改为user?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文