powershell - Script to convert multiple SID to readable username -
i have text file contain below detail, need on script can convert multiple sid readble username, i'm doubt coding.
window based permission file contain information below sample when open notepad
[/] 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
between, have found script convert sid how can use powershell change sid in csv user?
therefore, save file .csv , put heading first column user , second column permission
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
but getting error below when tried first powershell script, reply on hints post appreciated.
import-csv : cannot process argument because value of argument "name" invalid. change value of "name" argument , run operation again. @ line:1 char:19 +import-csv <<<< .\sid.csv | foreach-object{ + categoryinfo : invalidargument: (:) [import-csv], psargumentexception + fullyqualifiederrorid : argument,microsoft.powershell.commands.importcsvcommand
vbscript flavor:
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") each sid in sidlist set obj = wmi.get("win32_sid.sid='" & replace(sid, "=rw", "") & "'") wscript.echo obj.referenceddomainname & "\" & obj.accountname next
update: implement script filter this:
set wmi = getobject("winmgmts://./root/cimv2") until wscript.stdin.atendofstream line = trim(wscript.stdin.readline) if ucase(left(line, 2)) = "s-" set obj = wmi.get("win32_sid.sid='" & replace(sid, "=rw", "") & "'") wscript.stdout.writeline obj.referenceddomainname & "\" & obj.accountname end if loop
run filter this:
type input.txt | cscript //nologo filter.vbs > output.txt
note must use cscript.exe
or wont have access wscript.stdin
or wscript.stdout
.
Comments
Post a Comment