<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PowerShell.nu &#187; SID</title>
	<atom:link href="http://www.powershell.nu/tag/sid/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.powershell.nu</link>
	<description></description>
	<lastBuildDate>Wed, 14 Jul 2010 22:17:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>A Little on Security Identifiers ( SID ) using PowerShell</title>
		<link>http://www.powershell.nu/2009/01/19/a-little-on-security-identifiers-sid-using-powershell/</link>
		<comments>http://www.powershell.nu/2009/01/19/a-little-on-security-identifiers-sid-using-powershell/#comments</comments>
		<pubDate>Mon, 19 Jan 2009 21:25:03 +0000</pubDate>
		<dc:creator>Niklas Goude</dc:creator>
				<category><![CDATA[SID]]></category>

		<guid isPermaLink="false">http://www.powershell.nu/?p=358</guid>
		<description><![CDATA[A SID is used to identify a security principal or security group in Windows. SIDs are especially useful when troubleshooting security audits or migrations Starting of, lets look at the WMI Class Win32_UserAccount. This class can be used to retrieve a Users SID. PS > $Guest = gwmi Win32_UserAccount &#124; Where { $_.Name -like "Guest" [...]]]></description>
			<content:encoded><![CDATA[<p>A SID is used to identify a security principal or security group in Windows. SIDs are especially useful when troubleshooting security audits or migrations</p>
<p>Starting of, lets look at the WMI Class Win32_UserAccount. This class can be used to retrieve a Users SID.</p>
<p />
<pre>
<strong>
PS > $Guest = gwmi Win32_UserAccount | Where { $_.Name -like "Guest" }
PS > $Guest
</strong>

AccountType : 512
Caption     : APA\Guest
Domain      : APA
SID         : S-1-5-21-2827855531-1551796799-1404517278-501
FullName    :
Name        : Guest
</pre>
<p />
The Object contains even more informtaion that we might find useful:</p>
<p />
<pre>
<strong>
PS > $Guest | Format-List *
</strong>

Status             : Degraded
Caption            : APA\Guest
PasswordExpires    : False
__GENUS            : 2
__CLASS            : Win32_UserAccount
__SUPERCLASS       : Win32_Account
__DYNASTY          : CIM_ManagedSystemElement
__RELPATH          : Win32_UserAccount.Domain="APA",Name="Guest"
__PROPERTY_COUNT   : 16
__DERIVATION       : {Win32_Account, CIM_LogicalElement, CIM_ManagedSystemEleme
                     nt}
__SERVER           : SERVER1
__NAMESPACE        : root\cimv2
__PATH             : \\SERVER1\root\cimv2:Win32_UserAccount.Domain="APA",Name="
                     Guest"
AccountType        : 512
Description        : Built-in account for guest access to the computer/domain
Disabled           : True
Domain             : APA
FullName           :
InstallDate        :
LocalAccount       : False
Lockout            : False
Name               : Guest
PasswordChangeable : False
PasswordRequired   : False
SID                : S-1-5-21-2827855531-1551796799-1404517278-501
SIDType            : 1
Scope              : System.Management.ManagementScope
Path               : \\SERVER1\root\cimv2:Win32_UserAccount.Domain="APA",Name="
                     Guest"
Options            : System.Management.ObjectGetOptions
ClassPath          : \\SERVER1\root\cimv2:Win32_UserAccount
Properties         : {AccountType, Caption, Description, Disabled...}
SystemProperties   : {__GENUS, __CLASS, __SUPERCLASS, __DYNASTY...}
Qualifiers         : {dynamic, Locale, provider, UUID}
Site               :
Container          :
</pre>
<p />
If we only want sepcific information, we can pipe the object to the Select-Object CmdLet and specify what information we wnat to see.</p>
<p />
<pre>
<strong>
PS > $Guest | Select SID, Name, Description, Disabled, Domain
</strong>

SID         : S-1-5-21-2827855531-1551796799-1404517278-501
Name        : Guest
Description : Built-in account for guest access to the computer/domain
Disabled    : True
Domain      : APA
</pre>
<p />
If we know the Users SID but don&#8217;t know the Users Name, we can filter on the SID alphanumeric string instead.</p>
<p />
<pre>
<strong>
PS > $Guest = gwmi Win32_UserAccount |
>> where { $_.SID -like "S-1-5-21-2827855531-1551796799-1404517278-501" }
PS > $Guest
</strong>

AccountType : 512
Caption     : APA\Guest
Domain      : APA
SID         : S-1-5-21-2827855531-1551796799-1404517278-501
FullName    :
Name        : Guest
</pre>
<p />
Another nice trick is to use wildcards when filtering. Here i use 501 which is the &#8220;Guest&#8221; account. you can also filter on 500, &#8220;Administrator&#8221;. Here&#8217;s a link to Microsft that describes <a href="http://support.microsoft.com/kb/243330">Well-Known Security Identifiers</a>.</p>
<p />
<pre>
<strong>
PS > $Guest = gwmi Win32_UserAccount | where { $_.SID -like "*-501" }
PS > $Guest
</strong>

AccountType : 512
Caption     : APA\Guest
Domain      : APA
SID         : S-1-5-21-2827855531-1551796799-1404517278-501
FullName    :
Name        : Guest
</pre>
<p />
It&#8217;s also possible to use .NET System.Security to retrieve a Users SID. The .NET class takes Domain and AccountName as arguments. First we need to get the User.</p>
<p />
<pre>
<strong>
PS > $Guest = New-Object System.Security.Principal.NTAccount("APA.CORP","Guest")
PS > $Guest
</strong>
Value
-----
APA.CORP\Guest
</pre>
<p />
Next, we have to translate the User name to its SID.</p>
<p />
<pre>
<strong>
PS > $SID = $Guest.Translate([System.Security.Principal.SecurityIdentifier])
PS > $SID | Format-List *
</strong>

BinaryLength     : 28
AccountDomainSid : S-1-5-21-2827855531-1551796799-1404517278
Value            : S-1-5-21-2827855531-1551796799-1404517278-501
</pre>
<p />
Below is the code used in this Post.</p>
<p />
<pre>
<strong>
$Guest = gwmi Win32_UserAccount | Where { $_.Name -like "Guest" }
$Guest
$Guest | Select SID, Name, Description, Disabled, Domain

$Guest = gwmi Win32_UserAccount |
	where { $_.SID -like "S-1-5-21-2827855531-1551796799-1404517278-501" }
$Guest

$Guest = gwmi Win32_UserAccount | where { $_.SID -like "*-501" }
$Guest

$Guest = New-Object System.Security.Principal.NTAccount("APA.CORP","Guest")
$SID = $Guest.Translate([System.Security.Principal.SecurityIdentifier])
$SID | Format-List *
</strong>
</pre>
<p />
]]></content:encoded>
			<wfw:commentRss>http://www.powershell.nu/2009/01/19/a-little-on-security-identifiers-sid-using-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
