 




<?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 for Windows Admins &#187; Users</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/powershell/tag/users/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/powershell</link>
	<description>PowerShell and WMI: The fast and furious of windows administration.</description>
	<lastBuildDate>Fri, 24 May 2013 20:07:08 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Account SIDs</title>
		<link>http://itknowledgeexchange.techtarget.com/powershell/account-sids/</link>
		<comments>http://itknowledgeexchange.techtarget.com/powershell/account-sids/#comments</comments>
		<pubDate>Wed, 16 Jan 2013 22:21:13 +0000</pubDate>
		<dc:creator>Richard Siddaway</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Users]]></category>
		<category><![CDATA[WMI]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/powershell/?p=799</guid>
		<description><![CDATA[A question on the forum asked about finding the accounts and SIDs on the local machine. function get-SID { param ( [string]$computername = $env:COMPUTERNAME ) Get-WmiObject -Class Win32_AccountSID -ComputerName $computername &#124; foreach { $da = (($_.Element).Split(&#34;.&#34;)[1]).Split(&#34;,&#34;) $sid = ($_.Setting -split &#34;=&#34;)[1] -replace '&#34;','' $props = [ordered]@{ Domain = ($da[0] -split &#34;=&#34;)[1] -replace '&#34;','' Account = [...]]]></description>
				<content:encoded><![CDATA[<p>A question on the forum asked about finding the accounts and SIDs on the local machine.</p>
<pre><span style="color: #00008b">function</span> <span style="color: #8a2be2">get-SID</span> <span style="color: #000000">{</span>            
<span style="color: #00008b">param</span> <span style="color: #000000">(</span>            
 <span style="color: #008080">[string]</span><span style="color: #ff4500">$computername</span> <span style="color: #a9a9a9">=</span> <span style="color: #ff4500">$env:COMPUTERNAME</span>            
<span style="color: #000000">)</span>            
            
<span style="color: #0000ff">Get-WmiObject</span> <span style="color: #000080">-Class</span> <span style="color: #8a2be2">Win32_AccountSID</span> <span style="color: #000080">-ComputerName</span> <span style="color: #ff4500">$computername</span> <span style="color: #a9a9a9">|</span>            
<span style="color: #0000ff">foreach</span> <span style="color: #000000">{</span>            
 <span style="color: #ff4500">$da</span> <span style="color: #a9a9a9">=</span>  <span style="color: #000000">(</span><span style="color: #000000">(</span><span style="color: #ff4500">$_</span><span style="color: #a9a9a9">.</span><span style="color: #000000">Element</span><span style="color: #000000">)</span><span style="color: #a9a9a9">.</span><span style="color: #000000">Split</span><span style="color: #000000">(</span><span style="color: #8b0000">&quot;.&quot;</span><span style="color: #000000">)</span><span style="color: #a9a9a9">[</span><span style="color: #800080">1</span><span style="color: #a9a9a9">]</span><span style="color: #000000">)</span><span style="color: #a9a9a9">.</span><span style="color: #000000">Split</span><span style="color: #000000">(</span><span style="color: #8b0000">&quot;,&quot;</span><span style="color: #000000">)</span>            
 <span style="color: #ff4500">$sid</span> <span style="color: #a9a9a9">=</span> <span style="color: #000000">(</span><span style="color: #ff4500">$_</span><span style="color: #a9a9a9">.</span><span style="color: #000000">Setting</span> <span style="color: #a9a9a9">-split</span> <span style="color: #8b0000">&quot;=&quot;</span><span style="color: #000000">)</span><span style="color: #a9a9a9">[</span><span style="color: #800080">1</span><span style="color: #a9a9a9">]</span> <span style="color: #a9a9a9">-replace</span> <span style="color: #8b0000">'&quot;'</span><span style="color: #a9a9a9">,</span><span style="color: #8b0000">''</span>            
            
 <span style="color: #ff4500">$props</span> <span style="color: #a9a9a9">=</span> <span style="color: #008080">[ordered]</span><span style="color: #000000">@{</span>            
 <span style="color: #000000">Domain</span> <span style="color: #a9a9a9">=</span> <span style="color: #000000">(</span><span style="color: #ff4500">$da</span><span style="color: #a9a9a9">[</span><span style="color: #800080">0</span><span style="color: #a9a9a9">]</span> <span style="color: #a9a9a9">-split</span> <span style="color: #8b0000">&quot;=&quot;</span><span style="color: #000000">)</span><span style="color: #a9a9a9">[</span><span style="color: #800080">1</span><span style="color: #a9a9a9">]</span> <span style="color: #a9a9a9">-replace</span> <span style="color: #8b0000">'&quot;'</span><span style="color: #a9a9a9">,</span><span style="color: #8b0000">''</span>            
 <span style="color: #000000">Account</span> <span style="color: #a9a9a9">=</span> <span style="color: #000000">(</span><span style="color: #ff4500">$da</span><span style="color: #a9a9a9">[</span><span style="color: #800080">1</span><span style="color: #a9a9a9">]</span> <span style="color: #a9a9a9">-split</span> <span style="color: #8b0000">&quot;=&quot;</span><span style="color: #000000">)</span><span style="color: #a9a9a9">[</span><span style="color: #800080">1</span><span style="color: #a9a9a9">]</span> <span style="color: #a9a9a9">-replace</span> <span style="color: #8b0000">'&quot;'</span><span style="color: #a9a9a9">,</span><span style="color: #8b0000">''</span>            
 <span style="color: #000000">SID</span> <span style="color: #a9a9a9">=</span> <span style="color: #ff4500">$sid</span>            
 <span style="color: #000000">}</span>            
             
 <span style="color: #0000ff">New-Object</span> <span style="color: #000080">-TypeName</span> <span style="color: #8a2be2">PSObject</span> <span style="color: #000080">-Property</span> <span style="color: #ff4500">$props</span>            
<span style="color: #000000">}</span>            
            
<span style="color: #000000">}</span></pre>
<p>Pass a computer name into the function – default is local machine.</p>
<p>Use the AccountSID class which links Win32_SystemAccount and Win32_SID.&#160; For each returned instance clean up the data and create an object with three properties – domain, account and SID. </p>
<p>You will see more than you thought – some very useful information buried in there</p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/powershell/account-sids/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Working with profiles: 2 deleting profiles</title>
		<link>http://itknowledgeexchange.techtarget.com/powershell/working-with-profiles-2-deleting-profiles/</link>
		<comments>http://itknowledgeexchange.techtarget.com/powershell/working-with-profiles-2-deleting-profiles/#comments</comments>
		<pubDate>Fri, 08 Jun 2012 18:22:59 +0000</pubDate>
		<dc:creator>Richard Siddaway</dc:creator>
				<category><![CDATA[PowerShell 3]]></category>
		<category><![CDATA[PowerShell v2]]></category>
		<category><![CDATA[Users]]></category>
		<category><![CDATA[WMI]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/powershell/working-with-profiles-2-deleting-profiles/</guid>
		<description><![CDATA[I recently (1 June) showed how to discover the user profiles on your system. Now its time to delete them. function remove-profile { param ( [parameter(Mandatory=$true)] [string]$username ) $user = Get-CimInstance -Class Win32_UserAccount -Filter &#34;Name = '$username'&#34; $profile = Get-CimInstance -Class Win32_UserProfile -Filter &#34;SID = '$($user.SID)'&#34; $folder = Split-Path -Path $profile.LocalPath -Leaf if ($folder -eq [...]]]></description>
				<content:encoded><![CDATA[<p>I recently (1 June) showed how to discover the user profiles on your system. Now its time to delete them. </p>
<pre><span style="color: #00008b">function</span> <span style="color: #8a2be2">remove-profile</span> <span style="color: #000000">{</span>            
 <span style="color: #00008b">param</span> <span style="color: #000000">(</span>            
  <span style="color: #a9a9a9">[</span><span style="color: #00bfff">parameter</span><span style="color: #000000">(</span><span style="color: #000000">Mandatory</span><span style="color: #a9a9a9">=</span><span style="color: #ff4500">$true</span><span style="color: #000000">)</span><span style="color: #a9a9a9">]</span>            
  <span style="color: #008080">[string]</span><span style="color: #ff4500">$username</span>            
 <span style="color: #000000">)</span>            
            
 <span style="color: #ff4500">$user</span> <span style="color: #a9a9a9">=</span> <span style="color: #0000ff">Get-CimInstance</span> <span style="color: #000080">-Class</span> <span style="color: #8a2be2">Win32_UserAccount</span> <span style="color: #000080">-Filter</span> <span style="color: #8b0000">&quot;Name = '$username'&quot;</span>             
 <span style="color: #ff4500">$profile</span> <span style="color: #a9a9a9">=</span> <span style="color: #0000ff">Get-CimInstance</span> <span style="color: #000080">-Class</span> <span style="color: #8a2be2">Win32_UserProfile</span> <span style="color: #000080">-Filter</span> <span style="color: #8b0000">&quot;SID = '$($user.SID)'&quot;</span>            
 <span style="color: #ff4500">$folder</span> <span style="color: #a9a9a9">=</span> <span style="color: #0000ff">Split-Path</span> <span style="color: #000080">-Path</span> <span style="color: #ff4500">$profile</span><span style="color: #a9a9a9">.</span><span style="color: #000000">LocalPath</span> <span style="color: #000080">-Leaf</span>            
            
 <span style="color: #00008b">if</span> <span style="color: #000000">(</span><span style="color: #ff4500">$folder</span> <span style="color: #a9a9a9">-eq</span> <span style="color: #ff4500">$username</span><span style="color: #000000">)</span><span style="color: #000000">{</span>            
  <span style="color: #0000ff">Remove-CimInstance</span> <span style="color: #000080">-InputObject</span> <span style="color: #ff4500">$profile</span>            
 <span style="color: #000000">}</span>            
 <span style="color: #00008b">else</span> <span style="color: #000000">{</span>            
  <span style="color: #0000ff">Write-Warning</span> <span style="color: #000080">-Message</span> <span style="color: #8b0000">&quot;Could not resolve profile and user name&quot;</span>             
 <span style="color: #000000">}</span>            
            
<span style="color: #000000">}</span></pre>
<p>I’m going to start with the CIM cmdlets as these are the way of the future in PowerShell v3.</p>
<p>Start by taking a user name as a parameter. Get the Win32_UserAccount class object representing that account. use the SID to find the profile via Win32_UserProfile.&#160; Take the profile’s localpath and split it. The last part of the path should match the username – if it does then delete the profile otherwise throw a warning. Deleting the profile does delete the folder under c:\users</p>
<p>If you have to use the WMI cmdlets then its very similar</p>
<pre><span style="color: #00008b">function</span> <span style="color: #8a2be2">remove-profile</span> <span style="color: #000000">{</span>            
 <span style="color: #00008b">param</span> <span style="color: #000000">(</span>            
  <span style="color: #a9a9a9">[</span><span style="color: #00bfff">parameter</span><span style="color: #000000">(</span><span style="color: #000000">Mandatory</span><span style="color: #a9a9a9">=</span><span style="color: #ff4500">$true</span><span style="color: #000000">)</span><span style="color: #a9a9a9">]</span>            
  <span style="color: #008080">[string]</span><span style="color: #ff4500">$username</span>            
 <span style="color: #000000">)</span>            
            
 <span style="color: #ff4500">$user</span> <span style="color: #a9a9a9">=</span> <span style="color: #0000ff">Get-WmiObject</span> <span style="color: #000080">-Class</span> <span style="color: #8a2be2">Win32_UserAccount</span> <span style="color: #000080">-Filter</span> <span style="color: #8b0000">&quot;Name = '$username'&quot;</span>             
 <span style="color: #ff4500">$profile</span> <span style="color: #a9a9a9">=</span> <span style="color: #0000ff">Get-WmiObject</span> <span style="color: #000080">-Class</span> <span style="color: #8a2be2">Win32_UserProfile</span> <span style="color: #000080">-Filter</span> <span style="color: #8b0000">&quot;SID = '$($user.SID)'&quot;</span>            
 <span style="color: #ff4500">$folder</span> <span style="color: #a9a9a9">=</span> <span style="color: #0000ff">Split-Path</span> <span style="color: #000080">-Path</span> <span style="color: #ff4500">$profile</span><span style="color: #a9a9a9">.</span><span style="color: #000000">LocalPath</span> <span style="color: #000080">-Leaf</span>            
            
 <span style="color: #00008b">if</span> <span style="color: #000000">(</span><span style="color: #ff4500">$folder</span> <span style="color: #a9a9a9">-eq</span> <span style="color: #ff4500">$username</span><span style="color: #000000">)</span><span style="color: #000000">{</span>            
  <span style="color: #0000ff">Remove-WmiObject</span> <span style="color: #000080">-InputObject</span> <span style="color: #ff4500">$profile</span>            
 <span style="color: #000000">}</span>            
 <span style="color: #00008b">else</span> <span style="color: #000000">{</span>            
  <span style="color: #0000ff">Write-Warning</span> <span style="color: #000080">-Message</span> <span style="color: #8b0000">&quot;Could not resolve profile and user name&quot;</span>             
 <span style="color: #000000">}</span>            
            
<span style="color: #000000">}</span></pre>
<p>Just the name of the cmdlets change.</p>
<p>You can’t use WMI to delete local accounts as explained on page 363 of <a href="http://www.manning.com/powershellandwmi" target="_blank">PowerShell and WMI</a>&#160;</p>
<p>If you have profiles generated by AD accounts you’ll need to find the SID from the AD account and use that as the filter for deletion</p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/powershell/working-with-profiles-2-deleting-profiles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get the logged on users</title>
		<link>http://itknowledgeexchange.techtarget.com/powershell/get-the-logged-on-users/</link>
		<comments>http://itknowledgeexchange.techtarget.com/powershell/get-the-logged-on-users/#comments</comments>
		<pubDate>Tue, 17 Jan 2012 21:00:03 +0000</pubDate>
		<dc:creator>Richard Siddaway</dc:creator>
				<category><![CDATA[PowerShell v2]]></category>
		<category><![CDATA[Users]]></category>
		<category><![CDATA[WMI]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/powershell/get-the-logged-on-users/</guid>
		<description><![CDATA[Do you know which users are logged on to your systems? Want to find out? function get-logedonuser { param ( [string]$computername = $env:COMPUTERNAME ) Get-WmiObject -Class Win32_LogonSession -ComputerName $computername &#124; foreach { $data = $_ $id = $data.__RELPATH -replace &#34;&#34;&#34;&#34;, &#34;'&#34; $q = &#34;ASSOCIATORS OF {$id} WHERE ResultClass = Win32_Account&#34; Get-WmiObject -ComputerName $computername -Query $q [...]]]></description>
				<content:encoded><![CDATA[<p>Do you know which users are logged on to your systems?</p>
<p>Want to find out?</p>
<pre><span style="color: #00008b">function</span> <span style="color: #8a2be2">get-logedonuser</span> <span style="color: #000000">{</span>            
<span style="color: #00008b">param</span> <span style="color: #000000">(</span>            
 <span style="color: #008080">[string]</span><span style="color: #ff4500">$computername</span> <span style="color: #a9a9a9">=</span> <span style="color: #ff4500">$env:COMPUTERNAME</span>            
<span style="color: #000000">)</span>            
<span style="color: #0000ff">Get-WmiObject</span> <span style="color: #000080">-Class</span> <span style="color: #8a2be2">Win32_LogonSession</span> <span style="color: #000080">-ComputerName</span> <span style="color: #ff4500">$computername</span> <span style="color: #a9a9a9">|</span>            
<span style="color: #0000ff">foreach</span> <span style="color: #000000">{</span>            
 <span style="color: #ff4500">$data</span> <span style="color: #a9a9a9">=</span> <span style="color: #ff4500">$_</span>            
            
 <span style="color: #ff4500">$id</span> <span style="color: #a9a9a9">=</span> <span style="color: #ff4500">$data</span><span style="color: #a9a9a9">.</span><span style="color: #000000">__RELPATH</span> <span style="color: #a9a9a9">-replace</span> <span style="color: #8b0000">&quot;&quot;&quot;&quot;</span><span style="color: #a9a9a9">,</span> <span style="color: #8b0000">&quot;'&quot;</span>            
 <span style="color: #ff4500">$q</span> <span style="color: #a9a9a9">=</span> <span style="color: #8b0000">&quot;ASSOCIATORS OF {$id} WHERE ResultClass = Win32_Account&quot;</span>            
 <span style="color: #0000ff">Get-WmiObject</span> <span style="color: #000080">-ComputerName</span> <span style="color: #ff4500">$computername</span> <span style="color: #000080">-Query</span> <span style="color: #ff4500">$q</span> <span style="color: #a9a9a9">|</span>            
 <span style="color: #0000ff">select</span> <span style="color: #000000">@{</span><span style="color: #000000">N</span><span style="color: #a9a9a9">=</span><span style="color: #8b0000">&quot;User&quot;</span><span style="color: #000000">;</span><span style="color: #000000">E</span><span style="color: #a9a9a9">=</span><span style="color: #000000">{</span><span style="color: #000000">$(</span><span style="color: #ff4500">$_</span><span style="color: #a9a9a9">.</span><span style="color: #000000">Caption</span><span style="color: #000000">)</span><span style="color: #000000">}</span><span style="color: #000000">}</span><span style="color: #a9a9a9">,</span>             
 <span style="color: #000000">@{</span><span style="color: #000000">N</span><span style="color: #a9a9a9">=</span><span style="color: #8b0000">&quot;LogonTime&quot;</span><span style="color: #000000">;</span><span style="color: #000000">E</span><span style="color: #a9a9a9">=</span><span style="color: #000000">{</span><span style="color: #ff4500">$data</span><span style="color: #a9a9a9">.</span><span style="color: #000000">ConvertToDateTime</span><span style="color: #000000">(</span><span style="color: #ff4500">$data</span><span style="color: #a9a9a9">.</span><span style="color: #000000">StartTime</span><span style="color: #000000">)</span><span style="color: #000000">}</span><span style="color: #000000">}</span>            
<span style="color: #000000">}</span>            
<span style="color: #000000">}</span></pre>
<p>&#160;</p>
<p>Use the Win32_LogonSession class and then find the associated Win32_Account classes.&#160; It does work for domain and local accounts</p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/powershell/get-the-logged-on-users/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get Local Admins</title>
		<link>http://itknowledgeexchange.techtarget.com/powershell/get-local-admins/</link>
		<comments>http://itknowledgeexchange.techtarget.com/powershell/get-local-admins/#comments</comments>
		<pubDate>Mon, 05 Jul 2010 19:30:26 +0000</pubDate>
		<dc:creator>Richard Siddaway</dc:creator>
				<category><![CDATA[PowerShell v2]]></category>
		<category><![CDATA[Users]]></category>
		<category><![CDATA[WMI]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/powershell/get-local-admins/</guid>
		<description><![CDATA[I’ve been experimenting with different ways of retrieving local group membership – specifically the members of the local admin group. This is the quickest answer I’ve come up with 001 002 003 004 005 006 Get-WmiObject&#160;-Class&#160;Win32_GroupUser&#160;&#124;&#160; where{$_.GroupComponent&#160;-like&#160;&#34;*Administrators*&#34;}&#160;&#124;&#160; foreach&#160;{ &#160;&#160;&#160; $data&#160;=&#160;$_.PartComponent&#160;-split&#160;&#34;\,&#34; &#160;&#160;&#160; $data[1].Remove(0,5).Replace(&#8216;&#34;&#8217;,&#8221;)&#160; } The Win32_Usergroup is one of the association classes. In the case it [...]]]></description>
				<content:encoded><![CDATA[<p>I’ve been experimenting with different ways of retrieving local group membership – specifically the members of the local admin group.</p>
<p>This is the quickest answer I’ve come up with</p>
<div style="padding-bottom: 5px;padding-left: 5px;width: 456px;padding-right: 5px;font-family: consolas,lucida console;height: 153px;font-size: 10pt;padding-top: 5px">
<table border="0" cellspacing="0" cellpadding="5">
<tbody>
<tr>
<td valign="top">
<div style="padding-bottom: 5px;padding-left: 5px;padding-right: 5px;font-family: consolas,lucida console;font-size: 10pt;padding-top: 5px">001             <br />002              <br />003              <br />004              <br />005              <br />006              </div>
</td>
<td valign="top" nowrap="nowrap">
<div style="padding-bottom: 5px;padding-left: 5px;padding-right: 5px;font-family: consolas,lucida console;font-size: 10pt;padding-top: 5px"><span style="color: #0000ff">Get-WmiObject</span><span style="color: #000000">&#160;</span><span style="color: #000080">-Class</span><span style="color: #000000">&#160;</span><span style="color: #8a2be2">Win32_GroupUser</span><span style="color: #000000">&#160;</span><span style="color: #a9a9a9">|</span><span style="color: #000000">&#160;</span>              <br /><span style="color: #0000ff">where</span><span style="color: #000000">{</span><span style="color: #ff4500">$_</span><span style="color: #a9a9a9">.</span><span style="color: #000000">GroupComponent</span><span style="color: #000000">&#160;</span><span style="color: #a9a9a9">-like</span><span style="color: #000000">&#160;</span><span style="color: #8b0000">&quot;*Administrators*&quot;</span><span style="color: #000000">}</span><span style="color: #000000">&#160;</span><span style="color: #a9a9a9">|</span><span style="color: #000000">&#160;</span>              <br /><span style="color: #0000ff">foreach</span><span style="color: #000000">&#160;</span><span style="color: #000000">{</span>              <br /><span style="color: #000000">&#160;&#160;&#160; </span><span style="color: #ff4500">$data</span><span style="color: #000000">&#160;</span><span style="color: #a9a9a9">=</span><span style="color: #000000">&#160;</span><span style="color: #ff4500">$_</span><span style="color: #a9a9a9">.</span><span style="color: #000000">PartComponent</span><span style="color: #000000">&#160;</span><span style="color: #a9a9a9">-split</span><span style="color: #000000">&#160;</span><span style="color: #8b0000">&quot;\,&quot;</span>              <br /><span style="color: #000000">&#160;&#160;&#160; </span><span style="color: #ff4500">$data</span><span style="color: #a9a9a9">[</span><span style="color: #800080">1</span><span style="color: #a9a9a9">]</span><span style="color: #a9a9a9">.</span><span style="color: #000000">Remove</span><span style="color: #000000">(</span><span style="color: #800080">0</span><span style="color: #a9a9a9">,</span><span style="color: #800080">5</span><span style="color: #000000">)</span><span style="color: #a9a9a9">.</span><span style="color: #000000">Replace</span><span style="color: #000000">(</span><span style="color: #8b0000">&#8216;&quot;&#8217;</span><span style="color: #a9a9a9">,</span><span style="color: #8b0000">&#8221;</span><span style="color: #000000">)</span><span style="color: #000000">&#160;</span>              <br /><span style="color: #000000">}</span> </div>
</td>
</tr>
</tbody>
</table></div>
<p>The Win32_Usergroup is one of the association classes. In the case it has all the information we need.&#160; Use the GroupComponent to restrict the data to the admins groups.&#160; Split the Part component and then clean up the second element to get the name.</p>
<p>For reference the two elements look like this:</p>
<p>GroupComponent : \\RSLAPTOP01\root\cimv2:Win32_Group.Domain=&quot;RSLAPTOP01&quot;,Name=&quot;Administrators&quot;   </p>
<p>PartComponent&#160; : \\RSLAPTOP01\root\cimv2:Win32_UserAccount.Domain=&quot;RSLAPTOP01&quot;,Name=&quot;Administrator&quot;</p>
<p>If you want to pick off the domain to show the difference between local and domain accounts then manipulate $data[0]&#160; like this</p>
<div style="padding-bottom: 5px;padding-left: 5px;width: 463px;padding-right: 5px;font-family: consolas,lucida console;height: 221px;font-size: 10pt;padding-top: 5px">
<table border="0" cellspacing="0" cellpadding="5">
<tbody>
<tr>
<td valign="top">
<div style="padding-bottom: 5px;padding-left: 5px;padding-right: 5px;font-family: consolas,lucida console;font-size: 10pt;padding-top: 5px">001             <br />002              <br />003              <br />004              <br />005              <br />006              <br />007              <br />008              <br />009              <br />010              </div>
</td>
<td valign="top" nowrap="nowrap">
<div style="padding-bottom: 5px;padding-left: 5px;padding-right: 5px;font-family: consolas,lucida console;font-size: 10pt;padding-top: 5px"><span style="color: #0000ff">Get-WmiObject</span><span style="color: #000000">&#160;</span><span style="color: #000080">-Class</span><span style="color: #000000">&#160;</span><span style="color: #8a2be2">Win32_GroupUser</span><span style="color: #000000">&#160;</span><span style="color: #a9a9a9">|</span><span style="color: #000000">&#160;</span>              <br /><span style="color: #0000ff">where</span><span style="color: #000000">{</span><span style="color: #ff4500">$_</span><span style="color: #a9a9a9">.</span><span style="color: #000000">GroupComponent</span><span style="color: #000000">&#160;</span><span style="color: #a9a9a9">-like</span><span style="color: #000000">&#160;</span><span style="color: #8b0000">&quot;*Administrators*&quot;</span><span style="color: #000000">}</span><span style="color: #000000">&#160;</span><span style="color: #a9a9a9">|</span><span style="color: #000000">&#160;</span>              <br /><span style="color: #0000ff">foreach</span><span style="color: #000000">&#160;</span><span style="color: #000000">{</span>              <br /><span style="color: #000000">&#160;&#160;&#160; </span><span style="color: #ff4500">$data</span><span style="color: #000000">&#160;</span><span style="color: #a9a9a9">=</span><span style="color: #000000">&#160;</span><span style="color: #ff4500">$_</span><span style="color: #a9a9a9">.</span><span style="color: #000000">PartComponent</span><span style="color: #000000">&#160;</span><span style="color: #a9a9a9">-split</span><span style="color: #000000">&#160;</span><span style="color: #8b0000">&quot;\,&quot;</span>              <br /><span style="color: #000000">&#160;&#160;&#160; </span>              <br /><span style="color: #000000">&#160;&#160;&#160; </span><span style="color: #ff4500">$domain</span><span style="color: #000000">&#160;</span><span style="color: #a9a9a9">=</span><span style="color: #000000">&#160;</span><span style="color: #000000">(</span><span style="color: #ff4500">$data</span><span style="color: #a9a9a9">[</span><span style="color: #800080">0</span><span style="color: #a9a9a9">]</span><span style="color: #000000">&#160;</span><span style="color: #a9a9a9">-split</span><span style="color: #000000">&#160;</span><span style="color: #8b0000">&quot;=&quot;</span><span style="color: #000000">)</span><span style="color: #a9a9a9">[</span><span style="color: #800080">1</span><span style="color: #a9a9a9">]</span><span style="color: #a9a9a9">.</span><span style="color: #000000">Replace</span><span style="color: #000000">(</span><span style="color: #8b0000">&#8216;&quot;&#8217;</span><span style="color: #a9a9a9">,</span><span style="color: #8b0000">&#8221;</span><span style="color: #000000">)</span><span style="color: #000000">&#160;</span>              <br /><span style="color: #000000">&#160;&#160;&#160; </span><span style="color: #ff4500">$name</span><span style="color: #000000">&#160;</span><span style="color: #a9a9a9">=</span><span style="color: #000000">&#160;</span><span style="color: #ff4500">$data</span><span style="color: #a9a9a9">[</span><span style="color: #800080">1</span><span style="color: #a9a9a9">]</span><span style="color: #a9a9a9">.</span><span style="color: #000000">Remove</span><span style="color: #000000">(</span><span style="color: #800080">0</span><span style="color: #a9a9a9">,</span><span style="color: #800080">5</span><span style="color: #000000">)</span><span style="color: #a9a9a9">.</span><span style="color: #000000">Replace</span><span style="color: #000000">(</span><span style="color: #8b0000">&#8216;&quot;&#8217;</span><span style="color: #a9a9a9">,</span><span style="color: #8b0000">&#8221;</span><span style="color: #000000">)</span><span style="color: #000000">&#160;</span>              <br /><span style="color: #000000">&#160;&#160;&#160; </span>              <br /><span style="color: #000000">&#160;&#160;&#160; </span><span style="color: #8b0000">&quot;$domain\$name&quot;</span>              <br /><span style="color: #000000">}</span> </div>
</td>
</tr>
</tbody>
</table></div>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/powershell/get-local-admins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Desktop of current logged on user</title>
		<link>http://itknowledgeexchange.techtarget.com/powershell/desktop-of-current-logged-on-user/</link>
		<comments>http://itknowledgeexchange.techtarget.com/powershell/desktop-of-current-logged-on-user/#comments</comments>
		<pubDate>Mon, 26 Apr 2010 21:56:02 +0000</pubDate>
		<dc:creator>Richard Siddaway</dc:creator>
				<category><![CDATA[Users]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/powershell/desktop-of-current-logged-on-user/</guid>
		<description><![CDATA[&#160; In this post http://itknowledgeexchange.techtarget.com/powershell/current-logged-on-user/ we discovered how to find the current logged on user.&#160; I want to extend that a bit and add the information about that users desktop. We start with the script in our earlier post. 001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 [...]]]></description>
				<content:encoded><![CDATA[<p>&#160;</p>
<p>In this post <a title="http://itknowledgeexchange.techtarget.com/powershell/current-logged-on-user/" href="http://itknowledgeexchange.techtarget.com/powershell/current-logged-on-user/">http://itknowledgeexchange.techtarget.com/powershell/current-logged-on-user/</a> we discovered how to find the current logged on user.&#160; I want to extend that a bit and add the information about that users desktop.</p>
<p>We start with the script in our earlier post.</p>
<div style="padding-bottom: 5px;padding-left: 5px;width: 600px;padding-right: 5px;font-family: consolas,lucida console;height: 901px;font-size: 10pt;padding-top: 5px">
<table border="0" cellspacing="0" cellpadding="5">
<tbody>
<tr>
<td valign="top">
<div style="padding-bottom: 5px;padding-left: 5px;padding-right: 5px;font-family: consolas,lucida console;font-size: 10pt;padding-top: 5px">001             <br />002              <br />003              <br />004              <br />005              <br />006              <br />007              <br />008              <br />009              <br />010              <br />011              <br />012              <br />013              <br />014              <br />015              <br />016              <br />017              <br />018              <br />019              <br />020              <br />021              <br />022              <br />023              <br />024              <br />025              <br />026              <br />027              <br />028              <br />029              <br />030              <br />031              <br />032              <br />033              <br />034              <br />035              <br />036              <br />037              <br />038              <br />039              <br />040              <br />041              <br />042              <br />043              <br />044              <br />045              <br />046              <br />047              <br />048              <br />049              <br />050              </div>
</td>
<td valign="top" nowrap="nowrap">
<div style="padding-bottom: 5px;padding-left: 5px;padding-right: 5px;font-family: consolas,lucida console;font-size: 10pt;padding-top: 5px"><span style="color: #006400">## get session process</span>              <br /><span style="color: #ff4500">$proc</span><span style="color: #000000">&#160;</span><span style="color: #a9a9a9">=</span><span style="color: #000000">&#160;</span><span style="color: #0000ff">Get-WmiObject</span><span style="color: #000000">&#160;</span><span style="color: #000080">-Class</span><span style="color: #000000">&#160;</span><span style="color: #8a2be2">Win32_SessionProcess</span><span style="color: #000000">&#160;</span><span style="color: #a9a9a9">|</span><span style="color: #000000">&#160;</span>              <br /><span style="color: #0000ff">select</span><span style="color: #000000">&#160;</span><span style="color: #8a2be2">Antecedent</span><span style="color: #000000">&#160;</span><span style="color: #000080">-First</span><span style="color: #000000">&#160;</span><span style="color: #800080">1</span>              <br /><span style="color: #ff4500">$filt</span><span style="color: #000000">&#160;</span><span style="color: #a9a9a9">=</span><span style="color: #000000">&#160;</span><span style="color: #000000">(</span><span style="color: #ff4500">$proc</span><span style="color: #000000">&#160;</span><span style="color: #a9a9a9">-split</span><span style="color: #000000">&#160;</span><span style="color: #8b0000">&quot;=&quot;</span><span style="color: #000000">)</span><span style="color: #a9a9a9">[</span><span style="color: #800080">2</span><span style="color: #a9a9a9">]</span><span style="color: #000000">&#160;</span><span style="color: #a9a9a9">-replace</span><span style="color: #000000">&#160;</span><span style="color: #8b0000">&#8216;&quot;&#8217;</span><span style="color: #a9a9a9">,</span><span style="color: #8b0000">&#8221;</span><span style="color: #000000">&#160; </span><span style="color: #a9a9a9">-replace</span><span style="color: #000000">&#160;</span><span style="color: #8b0000">&quot;}&quot;</span><span style="color: #a9a9a9">,</span><span style="color: #8b0000">&quot;&quot;</span>              </p>
<p><span style="color: #ff4500">$ltype</span><span style="color: #000000">&#160;</span><span style="color: #a9a9a9">=</span><span style="color: #000000">&#160;</span><span style="color: #00008b">DATA</span><span style="color: #000000">&#160;</span><span style="color: #000000">{</span>              <br /><span style="color: #0000ff">ConvertFrom-StringData</span><span style="color: #000000">&#160;</span><span style="color: #000080">-StringData</span><span style="color: #000000">&#160;</span><span style="color: #8b0000">@&#8217;               <br />0 = System                <br />2 = Interactive                <br />3 = Network                <br />4 = Batch                <br />5 = Service                <br />6 = Proxy                <br />7 = Unlock                <br />8 = NetworkCleartext                <br />9 = NewCredentials                <br />10 = RemoteInteractive                <br />11 = CachedInteractive                <br />12 = CachedRemoteInteractive                <br />13 = CachedUnlock                <br />&#8216;@</span>              <br /><span style="color: #000000">}</span>              <br /><span style="color: #006400">## get logon session</span>              <br /><span style="color: #ff4500">$sess</span><span style="color: #000000">&#160;</span><span style="color: #a9a9a9">=</span><span style="color: #000000">&#160;</span><span style="color: #0000ff">Get-WmiObject</span><span style="color: #000000">&#160;</span><span style="color: #000080">-Class</span><span style="color: #000000">&#160;</span><span style="color: #8a2be2">Win32_LogonSession</span><span style="color: #000000">&#160;</span><span style="color: #000080">-Filter</span><span style="color: #000000">&#160;</span><span style="color: #8b0000">&quot;LogonId=&#8217;$filt&#8217;&quot;</span>              </p>
<p><span style="color: #006400">## get user</span>              <br /><span style="color: #ff4500">$query</span><span style="color: #000000">&#160;</span><span style="color: #a9a9a9">=</span><span style="color: #000000">&#160;</span><span style="color: #8b0000">&quot;ASSOCIATORS OF {Win32_LogonSession.LogonId=&#8217;$filt&#8217;}&quot;</span><span style="color: #000000">&#160;</span>`              <br /><span style="color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="color: #a9a9a9">+</span><span style="color: #000000">&#160;</span><span style="color: #8b0000">&quot;WHERE ResultClass=Win32_UserAccount&quot;</span>              <br /><span style="color: #ff4500">$user</span><span style="color: #000000">&#160;</span><span style="color: #a9a9a9">=</span><span style="color: #000000">&#160;</span><span style="color: #0000ff">Get-WmiObject</span><span style="color: #000000">&#160;</span><span style="color: #000080">-Query</span><span style="color: #000000">&#160; </span><span style="color: #ff4500">$query</span>              </p>
<p><span style="color: #ff4500">$query2</span><span style="color: #000000">&#160;</span><span style="color: #a9a9a9">=</span><span style="color: #000000">&#160;</span><span style="color: #8b0000">&quot;ASSOCIATORS OF {Win32_UserAccount.Domain=&#8217;$($user.Domain)&#8217;&quot;</span><span style="color: #000000">&#160;</span>`              <br /><span style="color: #000000">&#160; </span><span style="color: #a9a9a9">+</span><span style="color: #000000">&#160;</span><span style="color: #8b0000">&quot;,Name=&#8217;$($user.Name)&#8217;} WHERE ResultClass=Win32_Desktop&quot;</span>              </p>
<p><span style="color: #ff4500">$desktop</span><span style="color: #000000">&#160;</span><span style="color: #a9a9a9">=</span><span style="color: #000000">&#160;</span><span style="color: #0000ff">Get-WmiObject</span><span style="color: #000000">&#160;</span><span style="color: #000080">-Query</span><span style="color: #000000">&#160;</span><span style="color: #ff4500">$query2</span>              <br /><span style="color: #000000">&#160;</span>              <br /><span style="color: #0000ff">Add-Member</span><span style="color: #000000">&#160;</span><span style="color: #000080">-InputObject</span><span style="color: #000000">&#160;</span><span style="color: #ff4500">$sess</span><span style="color: #000000">&#160;</span><span style="color: #000080">-MemberType</span><span style="color: #000000">&#160;</span><span style="color: #8a2be2">NoteProperty</span><span style="color: #000000">&#160;</span><span style="color: #000080">-Name</span><span style="color: #000000">&#160;</span><span style="color: #8a2be2">User</span><span style="color: #000000">&#160;</span>`              <br /><span style="color: #000000">&#160;&#160; </span><span style="color: #000080">-Value</span><span style="color: #000000">&#160;</span><span style="color: #000000">$(</span><span style="color: #ff4500">$user</span><span style="color: #a9a9a9">.</span><span style="color: #000000">Caption</span><span style="color: #000000">)</span><span style="color: #000000">&#160;</span><span style="color: #000080">-PassThru</span><span style="color: #000000">&#160;</span><span style="color: #a9a9a9">|</span>              <br /><span style="color: #0000ff">Format-List</span><span style="color: #000000">&#160;</span><span style="color: #8a2be2">AuthenticationPackage</span><span style="color: #a9a9a9">,</span><span style="color: #000000">&#160;</span><span style="color: #8a2be2">LogonId</span><span style="color: #a9a9a9">,</span>              <br /><span style="color: #000000">@{</span><span style="color: #000000">Name</span><span style="color: #a9a9a9">=</span><span style="color: #8b0000">&quot;Logon Type&quot;</span><span style="color: #000000">;</span><span style="color: #000000">&#160;</span><span style="color: #000000">Expression</span><span style="color: #000000">&#160;</span><span style="color: #a9a9a9">=</span><span style="color: #000000">&#160;</span><span style="color: #000000">{</span><span style="color: #ff4500">$ltype</span><span style="color: #a9a9a9">[</span><span style="color: #8b0000">&quot;$($_.LogonType)&quot;</span><span style="color: #a9a9a9">]</span><span style="color: #000000">}</span><span style="color: #000000">}</span><span style="color: #a9a9a9">,</span>              <br /><span style="color: #000000">@{</span><span style="color: #000000">Name</span><span style="color: #a9a9a9">=</span><span style="color: #8b0000">&quot;Time&quot;</span><span style="color: #000000">;</span><span style="color: #000000">&#160;</span><span style="color: #000000">Expression</span><span style="color: #000000">&#160;</span><span style="color: #a9a9a9">=</span><span style="color: #000000">&#160;</span><span style="color: #000000">{</span><span style="color: #ff4500">$_</span><span style="color: #a9a9a9">.</span><span style="color: #000000">ConvertToDateTime</span><span style="color: #000000">(</span><span style="color: #ff4500">$_</span><span style="color: #a9a9a9">.</span><span style="color: #000000">StartTime</span><span style="color: #000000">)</span><span style="color: #000000">}</span><span style="color: #000000">}</span><span style="color: #a9a9a9">,</span>              <br /><span style="color: #8a2be2">User</span>              <br /><span style="color: #8b0000">&quot;Desktop Settings:&quot;</span>              <br /><span style="color: #ff4500">$desktop</span><span style="color: #000000">&#160;</span><span style="color: #a9a9a9">|</span><span style="color: #000000">&#160;</span><span style="color: #0000ff">Format-List</span><span style="color: #000000">&#160;</span><span style="color: #8a2be2">BorderWidth</span><span style="color: #a9a9a9">,</span><span style="color: #000000">&#160;</span><span style="color: #8a2be2">Caption</span><span style="color: #a9a9a9">,</span><span style="color: #000000">&#160;</span><span style="color: #8a2be2">CoolSwitch</span><span style="color: #a9a9a9">,</span>              <br /><span style="color: #8a2be2">CursorBlinkRate</span><span style="color: #a9a9a9">,</span><span style="color: #000000">&#160;</span><span style="color: #8a2be2">Description</span><span style="color: #a9a9a9">,</span><span style="color: #000000">&#160;</span><span style="color: #8a2be2">DragFullWindows</span><span style="color: #a9a9a9">,</span>              <br /><span style="color: #8a2be2">GridGranularity</span><span style="color: #a9a9a9">,</span><span style="color: #000000">&#160;</span><span style="color: #8a2be2">IconSpacing</span><span style="color: #a9a9a9">,</span><span style="color: #000000">&#160;</span><span style="color: #8a2be2">IconTitleFaceName</span><span style="color: #a9a9a9">,</span>              <br /><span style="color: #8a2be2">IconTitleSize</span><span style="color: #a9a9a9">,</span><span style="color: #000000">&#160;</span><span style="color: #8a2be2">IconTitleWrap</span><span style="color: #a9a9a9">,</span><span style="color: #000000">&#160;</span><span style="color: #8a2be2">Name</span><span style="color: #a9a9a9">,</span><span style="color: #000000">&#160;</span><span style="color: #8a2be2">Pattern</span><span style="color: #a9a9a9">,</span>              <br /><span style="color: #8a2be2">ScreenSaverActive</span><span style="color: #a9a9a9">,</span><span style="color: #000000">&#160;</span><span style="color: #8a2be2">ScreenSaverExecutable</span><span style="color: #a9a9a9">,</span>              <br /><span style="color: #8a2be2">ScreenSaverSecure</span><span style="color: #a9a9a9">,</span><span style="color: #000000">&#160;</span><span style="color: #8a2be2">ScreenSaverTimeout</span><span style="color: #a9a9a9">,</span>              <br /><span style="color: #8a2be2">SettingID</span><span style="color: #a9a9a9">,</span><span style="color: #000000">&#160;</span><span style="color: #8a2be2">Wallpaper</span><span style="color: #a9a9a9">,</span><span style="color: #000000">&#160;</span><span style="color: #8a2be2">WallpaperStretched</span><span style="color: #a9a9a9">,</span>              <br /><span style="color: #8a2be2">WallpaperTiled</span> </div>
</td>
</tr>
</tbody>
</table></div>
</p>
<p>We add a query to get the desktop associated with the current user&#160; &#8211; - $query2</p>
<p>That query returns the information about the desktop. Its displayed after the user information and I’ve selected the items I want to display.</p>
<p>This is a good example of extending an existing script when you find out how to do a bit more digging.</p>
<p>I think we’ve about exhausted the WMI information on users and groups for now – so its time to find another topic.</p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/powershell/desktop-of-current-logged-on-user/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows Groups</title>
		<link>http://itknowledgeexchange.techtarget.com/powershell/windows-groups/</link>
		<comments>http://itknowledgeexchange.techtarget.com/powershell/windows-groups/#comments</comments>
		<pubDate>Sat, 24 Apr 2010 21:32:53 +0000</pubDate>
		<dc:creator>Richard Siddaway</dc:creator>
				<category><![CDATA[PowerShell v2]]></category>
		<category><![CDATA[Users]]></category>
		<category><![CDATA[WMI]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/powershell/windows-groups/</guid>
		<description><![CDATA[  We can find the groups on a machine using WMI PS&#62; Get-WmiObject -Class Win32_Group &#124; select Name, Description, SID, LocalAccount &#124; format-list Name         : Administrators Description  : Administrators have complete and unrestricted access to the computer/domain SID          : S-1-5-32-544 LocalAccount : True etc etc But what would be good would if we could also [...]]]></description>
				<content:encoded><![CDATA[<p> </p>
<p>We can find the groups on a machine using WMI</p>
<p>PS&gt; Get-WmiObject -Class Win32_Group | select Name, Description, SID, LocalAccount | format-list</p>
<p>Name         : Administrators<br />
Description  : Administrators have complete and unrestricted access to the computer/domain<br />
SID          : S-1-5-32-544<br />
LocalAccount : True</p>
<p>etc etc</p>
<p>But what would be good would if we could also check membership at the same time</p>
<p> </p>
<div style="width: 464px;font-family: consolas,lucida console;height: 306px;font-size: 10pt;padding: 5px">
<table border="0" cellspacing="0" cellpadding="5">
<tbody>
<tr>
<td valign="top">
<div style="padding-bottom: 5px;padding-left: 5px;padding-right: 5px;font-family: consolas,lucida console;font-size: 10pt;padding-top: 5px">001<br />
002<br />
003<br />
004<br />
005<br />
006<br />
007<br />
008<br />
009<br />
010<br />
011<br />
012<br />
013<br />
014<br />
015</div>
</td>
<td valign="top">
<div style="padding-bottom: 5px;padding-left: 5px;padding-right: 5px;font-family: consolas,lucida console;font-size: 10pt;padding-top: 5px"><span style="color: #0000ff">Get-WmiObject</span><span style="color: #000000"> </span><span style="color: #000080">-Class</span><span style="color: #000000"> </span><span style="color: #8a2be2">Win32_Group</span><span style="color: #000000"> </span><span style="color: #a9a9a9">|</span><span style="color: #000000"> </span><br />
<span style="color: #0000ff">foreach</span><span style="color: #000000"> </span><span style="color: #000000">{</span><br />
<span style="color: #000000">    </span><span style="color: #8b0000">&#8220;`n$($_.Name)&#8221;</span><br />
<span style="color: #000000">    </span><span style="color: #8b0000">&#8220;$($_.Description)&#8221;</span><br />
<span style="color: #000000">    </span><span style="color: #8b0000">&#8220;SID: $($_.SID)&#8221;</span><br />
<span style="color: #000000">    </span><span style="color: #8b0000">&#8220;Local = $($_.LocalAccount)&#8221;</span><br />
<span style="color: #000000">    </span><span style="color: #8b0000">&#8220;Members:&#8221;</span><br />
<span style="color: #000000">    </span><br />
<span style="color: #000000">    </span><span style="color: #ff4500">$query</span><span style="color: #000000"> </span><span style="color: #a9a9a9">=</span><span style="color: #000000"> </span><span style="color: #8b0000">&#8220;ASSOCIATORS OF {Win32_Group.Domain=&#8217;&#8221;</span><span style="color: #000000"> </span>`<br />
<span style="color: #000000">    </span><span style="color: #a9a9a9">+</span><span style="color: #000000"> </span><span style="color: #ff4500">$_</span><span style="color: #a9a9a9">.</span><span style="color: #000000">Domain</span><span style="color: #000000"> </span><span style="color: #a9a9a9">+</span><span style="color: #000000"> </span><span style="color: #8b0000">&#8220;&#8216;,Name=&#8217;&#8221;</span><span style="color: #000000"> </span><span style="color: #a9a9a9">+</span><span style="color: #000000"> </span><span style="color: #ff4500">$_</span><span style="color: #a9a9a9">.</span><span style="color: #000000">Name</span><span style="color: #000000"> </span>`<br />
<span style="color: #000000">     </span><span style="color: #a9a9a9">+</span><span style="color: #000000"> </span><span style="color: #8b0000">&#8220;&#8216;} WHERE ResultClass=Win32_UserAccount&#8221;</span><span style="color: #000000">    </span><br />
<span style="color: #000000">    </span><span style="color: #0000ff">Get-WmiObject</span><span style="color: #000000"> </span><span style="color: #000080">-Query</span><span style="color: #000000"> </span><span style="color: #ff4500">$query</span><span style="color: #000000"> </span><span style="color: #a9a9a9">|</span><span style="color: #000000"> </span><br />
<span style="color: #000000">    </span><span style="color: #0000ff">select</span><span style="color: #000000"> </span><span style="color: #8a2be2">Caption</span></div>
<p><span style="color: #000000">}</span></td>
</tr>
</tbody>
</table>
</div>
<p>By now this format should be familiar.  We get the groups and for each group we use the ASSOCIATORS query to find the group members using the  Win32_UserAccount. We use string substitution to display the group information and display the caption property to get the domain and user name</p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/powershell/windows-groups/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>User Profiles</title>
		<link>http://itknowledgeexchange.techtarget.com/powershell/user-profiles/</link>
		<comments>http://itknowledgeexchange.techtarget.com/powershell/user-profiles/#comments</comments>
		<pubDate>Fri, 23 Apr 2010 20:04:10 +0000</pubDate>
		<dc:creator>Richard Siddaway</dc:creator>
				<category><![CDATA[PowerShell v2]]></category>
		<category><![CDATA[Users]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/powershell/user-profiles/</guid>
		<description><![CDATA[  Last time we looked at getting the currently logged on user. This time we’ll discover the user profiles that have been defined on our system. 001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 Get-WmiObject -Class Win32_UserProfile &#124;  foreach {     $query =  &#8220;ASSOCIATORS OF {Win32_SID.SID=&#8217;&#8221; `     [...]]]></description>
				<content:encoded><![CDATA[<p> </p>
<p>Last time we looked at getting the currently logged on user. This time we’ll discover the user profiles that have been defined on our system.</p>
<div style="width: 601px;font-family: consolas,lucida console;height: 408px;font-size: 10pt;padding: 5px">
<table border="0" cellspacing="0" cellpadding="5">
<tbody>
<tr>
<td valign="top">
<div style="padding-bottom: 5px;padding-left: 5px;padding-right: 5px;font-family: consolas,lucida console;font-size: 10pt;padding-top: 5px">001<br />
002<br />
003<br />
004<br />
005<br />
006<br />
007<br />
008<br />
009<br />
010<br />
011<br />
012<br />
013<br />
014<br />
015<br />
016<br />
017<br />
018<br />
019<br />
020<br />
021</div>
</td>
<td valign="top">
<div style="padding-bottom: 5px;padding-left: 5px;padding-right: 5px;font-family: consolas,lucida console;font-size: 10pt;padding-top: 5px"><span style="color: #0000ff">Get-WmiObject</span><span style="color: #000000"> </span><span style="color: #000080">-Class</span><span style="color: #000000"> </span><span style="color: #8a2be2">Win32_UserProfile</span><span style="color: #000000"> </span><span style="color: #a9a9a9">|</span><span style="color: #000000"> </span><br />
<span style="color: #0000ff">foreach</span><span style="color: #000000"> </span><span style="color: #000000">{</span><br />
<span style="color: #000000">    </span><span style="color: #ff4500">$query</span><span style="color: #000000"> </span><span style="color: #a9a9a9">=</span><span style="color: #000000">  </span><span style="color: #8b0000">&#8220;ASSOCIATORS OF {Win32_SID.SID=&#8217;&#8221;</span><span style="color: #000000"> </span>`<br />
<span style="color: #000000">    </span><span style="color: #a9a9a9">+</span><span style="color: #000000"> </span><span style="color: #ff4500">$_</span><span style="color: #a9a9a9">.</span><span style="color: #000000">Sid</span><span style="color: #000000"> </span><span style="color: #a9a9a9">+</span><span style="color: #000000"> </span><span style="color: #8b0000">&#8220;&#8216;} WHERE ResultClass=Win32_SystemAccount&#8221;</span><br />
<span style="color: #000000">      </span><br />
<span style="color: #000000">    </span><span style="color: #ff4500">$trustee</span><span style="color: #000000"> </span><span style="color: #a9a9a9">=</span><span style="color: #000000"> </span><span style="color: #0000ff">Get-WmiObject</span><span style="color: #000000"> </span><span style="color: #000080">-Query</span><span style="color: #000000"> </span><span style="color: #ff4500">$query</span><span style="color: #000000"> </span><br />
<span style="color: #000000">       </span><br />
<span style="color: #000000">    </span><span style="color: #00008b">if</span><span style="color: #000000">(</span><span style="color: #ff4500">$trustee</span><span style="color: #000000"> </span><span style="color: #a9a9a9">-eq</span><span style="color: #000000"> </span><span style="color: #ff4500">$null</span><span style="color: #000000">)</span><span style="color: #000000">{</span><br />
<span style="color: #000000">        </span><span style="color: #ff4500">$query</span><span style="color: #000000"> </span><span style="color: #a9a9a9">=</span><span style="color: #000000">  </span><span style="color: #8b0000">&#8220;ASSOCIATORS OF {Win32_SID.SID=&#8217;&#8221;</span><span style="color: #000000"> </span>`<br />
<span style="color: #000000">        </span><span style="color: #a9a9a9">+</span><span style="color: #000000"> </span><span style="color: #ff4500">$_</span><span style="color: #a9a9a9">.</span><span style="color: #000000">Sid</span><span style="color: #000000"> </span><span style="color: #a9a9a9">+</span><span style="color: #000000"> </span><span style="color: #8b0000">&#8220;&#8216;} WHERE ResultClass=Win32_UserAccount&#8221;</span><br />
<span style="color: #000000">        </span><span style="color: #ff4500">$trustee</span><span style="color: #000000"> </span><span style="color: #a9a9a9">=</span><span style="color: #000000"> </span><span style="color: #0000ff">Get-WmiObject</span><span style="color: #000000"> </span><span style="color: #000080">-Query</span><span style="color: #000000"> </span><span style="color: #ff4500">$query</span><span style="color: #000000"> </span><br />
<span style="color: #000000">    </span><span style="color: #000000">}</span><br />
<span style="color: #000000">    </span><span style="color: #0000ff">Add-Member</span><span style="color: #000000"> </span><span style="color: #000080">-InputObject</span><span style="color: #000000"> </span><span style="color: #ff4500">$_</span><span style="color: #000000"> </span><span style="color: #000080">-MemberType</span><span style="color: #000000"> </span><span style="color: #8a2be2">NoteProperty</span><span style="color: #000000"> </span><span style="color: #000080">-Name</span><span style="color: #000000"> </span><span style="color: #8a2be2">User</span><span style="color: #000000"> </span>`<br />
<span style="color: #000000">    </span><span style="color: #000080">-Value</span><span style="color: #000000"> </span><span style="color: #000000">$(</span><span style="color: #ff4500">$trustee</span><span style="color: #a9a9a9">.</span><span style="color: #000000">Caption</span><span style="color: #000000">)</span><span style="color: #000000"> </span><span style="color: #000080">-PassThru</span><br />
<span style="color: #000000">}</span><span style="color: #000000"> </span><span style="color: #a9a9a9">|</span><br />
<span style="color: #0000ff">Format-List</span><span style="color: #000000"> </span><span style="color: #8a2be2">User</span><span style="color: #a9a9a9">,</span><span style="color: #000000"> </span><span style="color: #8a2be2">Loaded</span><span style="color: #a9a9a9">,</span><span style="color: #000000"> </span><span style="color: #8a2be2">LocalPath</span><span style="color: #a9a9a9">,</span><span style="color: #000000"> </span><span style="color: #8a2be2">RoamingConfigured</span><span style="color: #a9a9a9">,</span><span style="color: #000000"> </span><span style="color: #8a2be2">RoamingPath</span><span style="color: #a9a9a9">,</span><br />
<span style="color: #8a2be2">RoamingPreference</span><span style="color: #a9a9a9">,</span><span style="color: #000000"> </span><span style="color: #8a2be2">Special</span><span style="color: #a9a9a9">,</span><span style="color: #000000"> </span><span style="color: #8a2be2">Status</span><span style="color: #a9a9a9">,</span><br />
<span style="color: #000000">@{</span><span style="color: #000000">Name</span><span style="color: #a9a9a9">=</span><span style="color: #8b0000">&#8220;Last Download&#8221;</span><span style="color: #000000">;</span><span style="color: #000000"> </span><br />
<span style="color: #000000"> </span><span style="color: #000000">Expression</span><span style="color: #a9a9a9">=</span><span style="color: #000000">{</span><span style="color: #ff4500">$_</span><span style="color: #a9a9a9">.</span><span style="color: #000000">ConvertToDateTime</span><span style="color: #000000">(</span><span style="color: #ff4500">$_</span><span style="color: #a9a9a9">.</span><span style="color: #000000">LastDownloadTime</span><span style="color: #000000">)</span><span style="color: #000000">}</span><span style="color: #000000">}</span><span style="color: #a9a9a9">,</span><br />
<span style="color: #000000">@{</span><span style="color: #000000">Name</span><span style="color: #a9a9a9">=</span><span style="color: #8b0000">&#8220;Last Upload&#8221;</span><span style="color: #000000">;</span><span style="color: #000000"> </span><span style="color: #000000">Expression</span><span style="color: #a9a9a9">=</span><span style="color: #000000">{</span><span style="color: #ff4500">$_</span><span style="color: #a9a9a9">.</span><span style="color: #000000">ConvertToDateTime</span><span style="color: #000000">(</span><span style="color: #ff4500">$_</span><span style="color: #a9a9a9">.</span><span style="color: #000000">LastUploadTime</span><span style="color: #000000">)</span><span style="color: #000000">}</span><span style="color: #000000">}</span><span style="color: #a9a9a9">,</span><br />
<span style="color: #000000">@{</span><span style="color: #000000">Name</span><span style="color: #a9a9a9">=</span><span style="color: #8b0000">&#8220;Last Used&#8221;</span><span style="color: #000000">;</span><span style="color: #000000"> </span><span style="color: #000000">Expression</span><span style="color: #a9a9a9">=</span><span style="color: #000000">{</span><span style="color: #ff4500">$_</span><span style="color: #a9a9a9">.</span><span style="color: #000000">ConvertToDateTime</span><span style="color: #000000">(</span><span style="color: #ff4500">$_</span><span style="color: #a9a9a9">.</span><span style="color: #000000">LastUseTime</span><span style="color: #000000">)</span><span style="color: #000000">}</span><span style="color: #000000">}</span></div>
</td>
</tr>
</tbody>
</table>
</div>
<p>We use Win32_UserProfile and foreach we find the user account associated with the SID – this is lifted straight from our look at share permissions. We use the technique from last time to add a property to the current object only this time are using the pipeline object (originally from our WMI query).</p>
<p>We can then pipe into Format-List and perform our display including converting the dates.</p>
<p>This class only appears to be available on Windows Vista SP1 and above – see <a title="http://msdn.microsoft.com/en-us/library/ee886409(VS.85).aspx" href="http://msdn.microsoft.com/en-us/library/ee886409(VS.85).aspx">http://msdn.microsoft.com/en-us/library/ee886409(VS.85).aspx</a> for details.</p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/powershell/user-profiles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Current logged on user</title>
		<link>http://itknowledgeexchange.techtarget.com/powershell/current-logged-on-user/</link>
		<comments>http://itknowledgeexchange.techtarget.com/powershell/current-logged-on-user/#comments</comments>
		<pubDate>Thu, 22 Apr 2010 21:08:23 +0000</pubDate>
		<dc:creator>Richard Siddaway</dc:creator>
				<category><![CDATA[PowerShell v2]]></category>
		<category><![CDATA[Users]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/powershell/current-logged-on-user/</guid>
		<description><![CDATA[in case you are wondering how I pick the topics for these posts – its quite scientific.  I run Get-WmiObject -List win32* &#124; where {$_.Name -notlike &#8220;*perf*&#8221;} to see the available classes and pick something that catches my eye. Sometimes it leads to a series of posts and other times its a single post. This [...]]]></description>
				<content:encoded><![CDATA[<p>in case you are wondering how I pick the topics for these posts – its quite scientific.  I run</p>
<p>Get-WmiObject -List win32* | where {$_.Name -notlike &#8220;*perf*&#8221;}</p>
<p>to see the available classes and pick something that catches my eye. Sometimes it leads to a series of posts and other times its a single post.</p>
<p>This time my eye was caught by Win32_LogonSession – which returns the logged on user</p>
<p>PS&gt; Get-WmiObject -Class Win32_LogonSession</p>
<p><span style="font-family: Courier New">AuthenticationPackage : NTLM<br />
LogonId               : 188568<br />
LogonType             : 2<br />
Name                  :<br />
StartTime             : 20100422181039.691600+060<br />
Status                : </span></p>
<p><span style="font-family: Courier New">AuthenticationPackage : NTLM<br />
LogonId               : 188537<br />
LogonType             : 2<br />
Name                  :<br />
StartTime             : 20100422181039.691600+060<br />
Status</span>                :</p>
<p>OK thats not good ‘cos I know I’m the only one logged in – unless its my imaginary friend</p>
<p>PS&gt; Get-WmiObject -Class Win32_SessionProcess | select Antecedent</p>
<p>Antecedent<br />
&#8212;&#8212;&#8212;-<br />
\\.\root\cimv2:Win32_LogonSession.LogonId=&#8221;188568&#8243;<br />
\\.\root\cimv2:Win32_LogonSession.LogonId=&#8221;188568&#8243;</p>
<p>etc</p>
<p>Shows that LogonId 188568 is the latest as Win32_SessionProcess shows the processes associated with the current logged on user.</p>
<p>We need to take that fact and find the logged on user</p>
<p> </p>
<div style="width: 599px;font-family: consolas,lucida console;height: 663px;font-size: 10pt;padding: 5px">
<table border="0" cellspacing="0" cellpadding="5">
<tbody>
<tr>
<td valign="top">
<div style="padding-bottom: 5px;padding-left: 5px;padding-right: 5px;font-family: consolas,lucida console;font-size: 10pt;padding-top: 5px">001<br />
002<br />
003<br />
004<br />
005<br />
006<br />
007<br />
008<br />
009<br />
010<br />
011<br />
012<br />
013<br />
014<br />
015<br />
016<br />
017<br />
018<br />
019<br />
020<br />
021<br />
022<br />
023<br />
024<br />
025<br />
026<br />
027<br />
028<br />
029<br />
030<br />
031<br />
032<br />
033<br />
034<br />
035<br />
036</div>
</td>
<td valign="top">
<div style="padding-bottom: 5px;padding-left: 5px;padding-right: 5px;font-family: consolas,lucida console;font-size: 10pt;padding-top: 5px"><span style="color: #006400">## get session process</span><br />
<span style="color: #ff4500">$proc</span><span style="color: #000000"> </span><span style="color: #a9a9a9">=</span><span style="color: #000000"> </span><span style="color: #0000ff">Get-WmiObject</span><span style="color: #000000"> </span><span style="color: #000080">-Class</span><span style="color: #000000"> </span><span style="color: #8a2be2">Win32_SessionProcess</span><span style="color: #000000"> </span><span style="color: #a9a9a9">|</span><span style="color: #000000"> </span><br />
<span style="color: #0000ff">select</span><span style="color: #000000"> </span><span style="color: #8a2be2">Antecedent</span><span style="color: #000000"> </span><span style="color: #000080">-First</span><span style="color: #000000"> </span><span style="color: #800080">1</span><br />
<span style="color: #ff4500">$filt</span><span style="color: #000000"> </span><span style="color: #a9a9a9">=</span><span style="color: #000000"> </span><span style="color: #000000">(</span><span style="color: #ff4500">$proc</span><span style="color: #000000"> </span><span style="color: #a9a9a9">-split</span><span style="color: #000000"> </span><span style="color: #8b0000">&#8220;=&#8221;</span><span style="color: #000000">)</span><span style="color: #a9a9a9">[</span><span style="color: #800080">2</span><span style="color: #a9a9a9">]</span><span style="color: #000000"> </span><span style="color: #a9a9a9">-replace</span><span style="color: #000000"> </span><span style="color: #8b0000">&#8216;&#8221;&#8216;</span><span style="color: #a9a9a9">,</span><span style="color: #8b0000">&#8221;</span><span style="color: #000000">  </span><span style="color: #a9a9a9">-replace</span><span style="color: #000000"> </span><span style="color: #8b0000">&#8220;}&#8221;</span><span style="color: #a9a9a9">,</span><span style="color: #8b0000">&#8220;&#8221;</span></div>
<p><span style="color: #ff4500">$ltype</span><span style="color: #000000"> </span><span style="color: #a9a9a9">=</span><span style="color: #000000"> </span><span style="color: #00008b">DATA</span><span style="color: #000000"> </span><span style="color: #000000">{</span><br />
<span style="color: #0000ff">ConvertFrom-StringData</span><span style="color: #000000"> </span><span style="color: #000080">-StringData</span><span style="color: #000000"> </span><span style="color: #8b0000">@&#8217;<br />
0 = System<br />
2 = Interactive<br />
3 = Network<br />
4 = Batch<br />
5 = Service<br />
6 = Proxy<br />
7 = Unlock<br />
8 = NetworkCleartext<br />
9 = NewCredentials<br />
10 = RemoteInteractive<br />
11 = CachedInteractive<br />
12 = CachedRemoteInteractive<br />
13 = CachedUnlock<br />
&#8216;@</span><br />
<span style="color: #000000">}</span><br />
<span style="color: #006400">## get logon session</span><br />
<span style="color: #ff4500">$sess</span><span style="color: #000000"> </span><span style="color: #a9a9a9">=</span><span style="color: #000000"> </span><span style="color: #0000ff">Get-WmiObject</span><span style="color: #000000"> </span><span style="color: #000080">-Class</span><span style="color: #000000"> </span><span style="color: #8a2be2">Win32_LogonSession</span><span style="color: #000000"> </span><span style="color: #000080">-Filter</span><span style="color: #000000"> </span><span style="color: #8b0000">&#8220;LogonId=&#8217;$filt&#8217;&#8221;</span></p>
<p><span style="color: #006400">## get user</span><br />
<span style="color: #ff4500">$query</span><span style="color: #000000"> </span><span style="color: #a9a9a9">=</span><span style="color: #000000"> </span><span style="color: #8b0000">&#8220;ASSOCIATORS OF {Win32_LogonSession.LogonId=&#8217;$filt&#8217;} `<br />
WHERE ResultClass=Win32_UserAccount&#8221;</span><br />
<span style="color: #ff4500">$user</span><span style="color: #000000"> </span><span style="color: #a9a9a9">=</span><span style="color: #000000"> </span><span style="color: #0000ff">Get-WmiObject</span><span style="color: #000000"> </span><span style="color: #000080">-Query</span><span style="color: #000000">  </span><span style="color: #ff4500">$query</span><br />
<span style="color: #000000"> </span><br />
<span style="color: #0000ff">Add-Member</span><span style="color: #000000"> </span><span style="color: #000080">-InputObject</span><span style="color: #000000"> </span><span style="color: #ff4500">$sess</span><span style="color: #000000"> </span><span style="color: #000080">-MemberType</span><span style="color: #000000"> </span><span style="color: #8a2be2">NoteProperty</span><span style="color: #000000"> </span><span style="color: #000080">-Name</span><span style="color: #000000"> </span><span style="color: #8a2be2">User</span><span style="color: #000000"> </span>`<br />
<span style="color: #000000"> </span><span style="color: #000080">-Value</span><span style="color: #000000"> </span><span style="color: #000000">$(</span><span style="color: #ff4500">$user</span><span style="color: #a9a9a9">.</span><span style="color: #000000">Caption</span><span style="color: #000000">)</span><span style="color: #000000"> </span><span style="color: #000080">-PassThru</span><span style="color: #000000"> </span><span style="color: #a9a9a9">|</span><br />
<span style="color: #0000ff">Format-List</span><span style="color: #000000"> </span><span style="color: #8a2be2">AuthenticationPackage</span><span style="color: #a9a9a9">,</span><span style="color: #000000"> </span><span style="color: #8a2be2">LogonId</span><span style="color: #a9a9a9">,</span><br />
<span style="color: #000000">@{</span><span style="color: #000000">Name</span><span style="color: #a9a9a9">=</span><span style="color: #8b0000">&#8220;Logon Type&#8221;</span><span style="color: #000000">;</span><span style="color: #000000"> </span><span style="color: #000000">Expression</span><span style="color: #000000"> </span><span style="color: #a9a9a9">=</span><span style="color: #000000"> </span><span style="color: #000000">{</span><span style="color: #ff4500">$ltype</span><span style="color: #a9a9a9">[</span><span style="color: #8b0000">"$($_.LogonType)"</span><span style="color: #a9a9a9">]</span><span style="color: #000000">}</span><span style="color: #000000">}</span><span style="color: #a9a9a9">,</span><br />
<span style="color: #000000">@{</span><span style="color: #000000">Name</span><span style="color: #a9a9a9">=</span><span style="color: #8b0000">&#8220;Time&#8221;</span><span style="color: #000000">;</span><span style="color: #000000"> </span><span style="color: #000000">Expression</span><span style="color: #000000"> </span><span style="color: #a9a9a9">=</span><span style="color: #000000"> </span><span style="color: #000000">{</span><span style="color: #ff4500">$_</span><span style="color: #a9a9a9">.</span><span style="color: #000000">ConvertToDateTime</span><span style="color: #000000">(</span><span style="color: #ff4500">$_</span><span style="color: #a9a9a9">.</span><span style="color: #000000">StartTime</span><span style="color: #000000">)</span><span style="color: #000000">}</span><span style="color: #000000">}</span><span style="color: #a9a9a9">,</span><br />
<span style="color: #8a2be2">User</span></td>
</tr>
</tbody>
</table>
</div>
<p>We take our session process – select first 1 and we only need the Antecedent property. We then split it on a “=” sign and do 2 replaces to clean it up.  I was surprised when the operators combined like that.</p>
<p>The here-string defines a the logon types. We find the Win32_LogonSession associated with the logonid and then get the ASSOCIATORS to find the associated user.</p>
<p>We use Add-Member to add the user name property to the session information and then use a couple of calculated fields to display the logon type and the logon date</p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/powershell/current-logged-on-user/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
