tags:

views:

83

answers:

1

Hallo. If I run this code

$server = "."
$adsi = [ADSI]"WinNT://$server" 
$adsi.psbase.children | where {$_.schemaClassName -match "user"} | select name, objectsid |Format-Table -auto

I get object sid in this form

1 5 0 0 0 0 0 5 21 0 0 0 138 93 63 151 163 49 215 2 60 164 164 50 236 3 0 0

I'd like to know if it's possible to convert it to get the same result that you have from win32_useraccount class. Thanks in advance

+1  A: 
$adsi.psbase.children | where {$_.schemaClassName -match "user"} | foreach-object{    
  $account = New-Object Security.Principal.NTAccount $_.name
  $account.Translate( [Security.Principal.Securityidentifier] ).Value
}
Shay Levy
Hi Shay. Thank you very much. I was looking for a way to find the name of admin account. $server = "."$adsi = [ADSI]"WinNT://$server" $admin = $adsi.psbase.children | where {$_.schemaClassName -match "user"} | % { $account = New-Object Security.Principal.NTAccount $_.name New-Object PSObject -Property @{ name = $_.Name sid = $account.translate( [Security.Principal.Securityidentifier] ).Value } | ? {$_.sid.endswith('-500')} | % {$_.name}} $admin
anfrasa
As soon as I'll reach the minimum score necessary I'll vote you. Thanks again.
anfrasa
bind to the administrator account and get its name. In powershell v1 you may have to add psbase first ($admin.psbase.name)$admin = [adsi]"WinNT:///$server/administrator,user"$admin.name
Shay Levy
With the following one-liner you can get the name and sid of the admin account: $admin | select @{n='Name';e={$_.Name}}, @{n='SID';e={(New-Object Security.Principal.NTAccount $_.name).translate( [Security.Principal.Securityidentifier] ).Value }}
Shay Levy
Thanks again Shay and congratulations for your blog that is really interesting ;)
anfrasa