我有一个包含以下详细信息的文本文件,所以我需要有关可以将多个SID转换为可读用户名的脚本的帮助,但我真的怀疑编码。
基于窗口的权限文件包含使用记事本打开时的以下信息
[/]
S-1-5-21-1449722967-1661817991-10773629-12231=rw
S-1-5-21-1449722967-1661817991-10773629-15527=rw
[AM_ATTG:/]
S-1-5-21-1449722967-1661817991-10773629-1207=rw
之间,我找到了从How can I use powershell to change sid in csv to user?
转换SID的脚本因此,我将文件保存到.csv并将标题添加到第一列作为用户和第二列作为权限
User Permission
[/]
S-1-5-21-1449722967-1661817991-10773629-12231 rw
S-1-5-21-1449722967-1661817991-10773629-15527 rw
[AM_ATTG:/]
S-1-5-21-1449722967-1661817991-10773629-1207 rw
但是在尝试第一个powershell脚本时我收到了以下错误,非常感谢您对我的帖子的任何提示的回复。
Import-Csv : Cannot process argument because the value of argument "name" is invalid. Change the value of the "name" argument and run the operation again.
At line:1 char:19
+Import-Csv <<<< .\sid.csv | ForEach-Object{
+ CategoryInfo : InvalidArgument: (:) [Import-Csv], PSArgumentException
+ FullyQualifiedErrorId : Argument,Microsoft.PowerShell.Commands.ImportCsvCommand
答案 0 :(得分:0)
我建议你让csv文件看起来像那样(用逗号分隔):
Sid,Permission
S-1-5-21-1449722967-1661817991-10773629-12231,rw
S-1-5-21-1449722967-1661817991-10773629-15527,rw
S-1-5-21-1449722967-1661817991-10773629-1207,rw
然后你可以这样做:
Import-Csv SID.csv |
Select-Object Sid,Permission,@{n='User';e={(New-Object System.Security.Principal.SecurityIdentifier $_.Sid).Translate([System.Security.Principal.NTAccount]).Value}}
答案 1 :(得分:0)
VBScript风味:
sidList = Array( "S-1-5-21-1449722967-1661817991-10773629-12231=rw" _
, "S-1-5-21-1449722967-1661817991-10773629-15527=rw" _
, "S-1-5-21-1449722967-1661817991-10773629-1207=rw" _
)
Set wmi = GetObject("winmgmts://./root/cimv2")
For Each sid In sidList
Set obj = wmi.Get("Win32_SID.SID='" & Replace(sid, "=rw", "") & "'")
WScript.Echo obj.ReferencedDomainName & "\" & obj.AccountName
Next
更新:您可以将脚本实现为这样的过滤器:
Set wmi = GetObject("winmgmts://./root/cimv2")
Do Until WScript.StdIn.AtEndOfStream
line = Trim(WScript.StdIn.ReadLine)
If UCase(Left(line, 2)) = "S-" Then
Set obj = wmi.Get("Win32_SID.SID='" & Replace(sid, "=rw", "") & "'")
WScript.StdOut.WriteLine obj.ReferencedDomainName & "\" & obj.AccountName
End If
Loop
像这样运行过滤器:
type input.txt | cscript //NoLogo filter.vbs > output.txt
请注意,您必须使用cscript.exe
,否则您将无法访问WScript.StdIn
或WScript.StdOut
。