<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://powershell.com/cs/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results for 'app:weblogs' matching tags 'WMI' and 'desktop management'</title><link>http://powershell.com/cs/search/SearchResults.aspx?q=app:weblogs&amp;tag=WMI,desktop+management&amp;orTags=0&amp;o=DateDescending</link><description>Search results for 'app:weblogs' matching tags 'WMI' and 'desktop management'</description><dc:language>en-US</dc:language><generator>CommunityServer 2008.5 (Build: 30929.2835)</generator><item><title>Use PowerShell to Find Detailed Windows Profile Information</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2013/03/04/use-powershell-to-find-detailed-windows-profile-information.aspx</link><pubDate>Mon, 04 Mar 2013 06:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:21940</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&lt;strong&gt;Summary:&lt;/strong&gt; Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to find detailed Windows profile information.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://img.microsoft.com/library/media/1033/technet/images/scriptcenter/qanda/q-sm.jpg" alt="Hey, Scripting Guy! Question" /&gt;&amp;nbsp;Hey, Scripting Guy! I am in a bind. I need to find out who is using what profile on a desktop computer. I also need to find out when the profile was last used. This is because many of the computers in our lab have rather small hard disk drives, and these drives are nearly filled up with user profiles. After I know who has been using a profile and when it was last used, I can decide if I want to remove the profile.&lt;/p&gt;
&lt;p&gt;&amp;mdash;KG&lt;/p&gt;
&lt;p&gt;&lt;img src="http://img.microsoft.com/library/media/1033/technet/images/scriptcenter/qanda/a-sm.jpg" alt="Hey, Scripting Guy! Answer" /&gt;&amp;nbsp;Hello KG,&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. It is a new week for the Hey, Scripting Guy! Blog. It is also a new month. This means that this Thursday, March 7, 2013 we will have our &lt;a href="http://powershellgroup.org/charlotte.nc" target="_blank"&gt;Charlotte Windows PowerShell User Group&lt;/a&gt; meeting at the Microsoft office. If you are in the area, check it out. You will need to register first so we know how much food to purchase. It is always a lot of fun, and we will be playing a mini Scripting Game.&lt;/p&gt;
&lt;p&gt;KG, your request is a reasonable one. To find user profile information, I use WMI.&lt;/p&gt;
&lt;h2&gt;Finding user profile information&lt;/h2&gt;
&lt;p&gt;To find user profile information, I use the Win32_UserProfile WMI class. To query the Win32_UserProfile WMI class, I can use the &lt;strong&gt;Get-WmiObject&lt;/strong&gt; cmdlet. This technique is shown here (&lt;strong&gt;gwmi&lt;/strong&gt; is an alias for &lt;strong&gt;Get-WmiObject&lt;/strong&gt;).&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;gwmi win32_userprofile&lt;/p&gt;
&lt;p&gt;The command and its associated output are shown here.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/1738.HSG_2D00_3_2D00_4_2D00_13_2D00_01.png"&gt;&lt;img title="Image of command output" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/1738.HSG_2D00_3_2D00_4_2D00_13_2D00_01.png" alt="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;There is a lot of information that I am not interested in examining. In fact, what I really need is &lt;strong&gt;LastUseTime&lt;/strong&gt;, &lt;strong&gt;LocalPath&lt;/strong&gt;, and &lt;strong&gt;SID&lt;/strong&gt;. The revised query is shown here.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;gwmi win32_userprofile | select lastusetime, localpath, sid&lt;/p&gt;
&lt;p&gt;The revised command and its output are shown here.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/6521.HSG_2D00_3_2D00_4_2D00_13_2D00_02.png"&gt;&lt;img title="Image of command output" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/6521.HSG_2D00_3_2D00_4_2D00_13_2D00_02.png" alt="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;But I need something a bit easier to read. Also, I am not interested in profiles that are not used. In Windows PowerShell&amp;nbsp;3.0, the &lt;strong&gt;Get-CimInstance&lt;/strong&gt; cmdlet translates the time. This brings me a step closer to what I need. Here is the command.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;get-ciminstance win32_userprofile | ? lastusetime | select lastusetime, localpath, sid&lt;/p&gt;
&lt;p&gt;The command and its output are shown here.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/4370.HSG_2D00_3_2D00_4_2D00_13_2D00_03.png"&gt;&lt;img title="Image of command output" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/4370.HSG_2D00_3_2D00_4_2D00_13_2D00_03.png" alt="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Translating SID to a user&lt;/h2&gt;
&lt;p&gt;Groovy. Now I need to translate the SID to a readable user account, and I am home free. There are several ways to translate a SID to a user account. One way to do this is to use the Win32_UserAccount WMI class. It is easy to do&amp;mdash;and hey, I am already messing around with WMI.&lt;/p&gt;
&lt;p&gt;So how does it work? Well, the Win32_UserAccount WMI class has a &lt;strong&gt;SID&lt;/strong&gt; property in addition to a &lt;strong&gt;Name&lt;/strong&gt; property. But I like to use &lt;strong&gt;Caption&lt;/strong&gt; because it has both the domain and the name in it. So I filter on the &lt;strong&gt;SID&lt;/strong&gt;, and boom it works. Here are a couple of examples:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS C:\&amp;gt; (gwmi win32_useraccount -Filter &amp;quot;sid = &amp;#39;S-1-5-21-1457956834-3844189528-354135&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;0385-1613&amp;#39;&amp;quot;).name&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Tim O&amp;#39;Brian&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS C:\&amp;gt; (gwmi win32_useraccount -Filter &amp;quot;sid = &amp;#39;S-1-5-21-1457956834-3844189528-354135&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;0385-1613&amp;#39;&amp;quot;).Caption&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;IAMMRED\Tim O&amp;#39;Brian&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS C:\&amp;gt;&lt;/p&gt;
&lt;p&gt;Sweet, so now all I need to do is to create a custom property on my custom object, and I am good to go.&lt;/p&gt;
&lt;h2&gt;Create custom object with required info&lt;/h2&gt;
&lt;p&gt;I need to create a custom object with the &lt;strong&gt;LastUseTime&lt;/strong&gt; property, the &lt;strong&gt;LocalPath&lt;/strong&gt;, and the user name. To do this, I use the &lt;strong&gt;Select-Object&lt;/strong&gt; cmdlet. I choose the &lt;strong&gt;LastUseTime&lt;/strong&gt; property and the &lt;strong&gt;LocalPath&lt;/strong&gt; property. I then use a hash table to resolve the SID to a user account name. Here is the hash table I use:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;@{LABEL=&amp;#39;user&amp;#39;;EXPRESSION={(gwmi win32_useraccount -filter &amp;quot;SID = &amp;#39;$($_.sid)&amp;#39;&amp;quot;).caption}}&lt;/p&gt;
&lt;p&gt;Now, what I am doing in the expression is using WMI to query the Win32_UserAccount WMI class. I specify the filter as &lt;strong&gt;Sid = &amp;lsquo;$($_.sid)&amp;rsquo;&lt;/strong&gt;. I need the subexpression here to keep the WMI SID property from unraveling. Because the query returns a user account object, and I only want the caption, I group the expression and select only the &lt;strong&gt;Caption&lt;/strong&gt; property. The entire command is shown here (it is a single line command):&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;get-ciminstance win32_userprofile |&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;? lastusetime |&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;select lastusetime, localpath,&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;@{LABEL=&amp;#39;user&amp;#39;;EXPRESSION={(gwmi win32_useraccount -filter &amp;quot;SID = &amp;#39;$($_.sid)&amp;#39;&amp;quot;).caption}}&lt;/p&gt;
&lt;p&gt;The complete command and the output from the command are shown in the image that follows.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/4454.HSG_2D00_3_2D00_4_2D00_13_2D00_04.png"&gt;&lt;img title="Image of command output" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/4454.HSG_2D00_3_2D00_4_2D00_13_2D00_04.png" alt="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;KG, that is all there is to using Windows PowerShell and WMI to return user profile stuff. Join me tomorrow when I will talk about more cool Windows PowerShell stuff.&lt;/p&gt;
&lt;p&gt;I invite you to follow me on &lt;a href="http://bit.ly/scriptingguystwitter" target="_blank"&gt;Twitter&lt;/a&gt; and &lt;a href="http://bit.ly/scriptingguysfacebook" target="_blank"&gt;Facebook&lt;/a&gt;. If you have any questions, send email to me at &lt;a href="mailto:scripter@microsoft.com" target="_blank"&gt;scripter@microsoft.com&lt;/a&gt;, or post your questions on the &lt;a href="http://bit.ly/scriptingforum" target="_blank"&gt;Official Scripting Guys Forum&lt;/a&gt;. See you tomorrow. Until then, peace.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Ed Wilson, Microsoft Scripting Guy&lt;/strong&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3555145" width="1" height="1" alt="" /&gt;</description></item><item><title>Use PowerShell to Detect Power State and to Set Power Plan</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2012/11/28/use-powershell-to-detect-power-state-and-to-set-power-plan.aspx</link><pubDate>Wed, 28 Nov 2012 06:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:20279</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&lt;strong&gt;Summary:&lt;/strong&gt; Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to detect the power state on his laptop and to set the appropriate power plan.&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. This evening in Oslo, Norway, the Scripting Wife and I are attending the &lt;a href="http://www.mtug.no/Forside/tabid/58/aid/15/language/nb-NO/Default.aspx" target="_blank"&gt;Microsoft Technology User Group meeting&lt;/a&gt;. The meeting runs from 18:00 until 20:00 (CET). Interestingly enough, the lows in Oslo and in Charlotte, North Carolina, are about the same. The big difference is the 30-degree temperature between high and low in Charlotte. Oh well, and the other big difference is a bit of snow! WOO HOO!!!&lt;/p&gt;
&lt;h2&gt;Detect power state by using PowerShell&lt;/h2&gt;
&lt;p&gt;To detect whether or not my laptop is running on battery, I can query the &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa394074(v=vs.85).aspx" target="_blank"&gt;Win32_Battery WMI class&lt;/a&gt;. This WMI class is in the Root\CimV2 WMI namespace and has been around since forever. There is nothing special about this class. The only thing is to ensure that my laptop actually populates information in the class&amp;mdash;and that the information is reliable.&lt;/p&gt;
&lt;p&gt;In the past, I have had laptops in which the Win32_Battery WMI class did not populate at all when the laptop was plugged into electricity; it only became available when the laptop ran on battery. There is another WMI class&amp;mdash;Win32_Portablebattery. This WMI class also derives from Cim_Battery, but it provides a bit more information than Win32_Battery. On the other hand, Win32_Battery provides information about recharge status. The differences are shown here.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS C:\&amp;gt; $b = Get-CimClass win32_battery&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS C:\&amp;gt; $p = Get-CimClass win32_portablebattery&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS C:\&amp;gt; Compare-Object $b.CimClassProperties.name $p.CimClassProperties.name&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;InputObject&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SideIndicator&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;-----------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -------------&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;CapacityMultiplier&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Location&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;=&amp;gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;ManufactureDate&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Manufacturer&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;MaxBatteryError&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;BatteryRechargeTime&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;=&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;ExpectedBatteryLife&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;=&lt;/p&gt;
&lt;h2&gt;The battery is discharging&lt;/h2&gt;
&lt;p&gt;If the laptop runs on the battery, the &lt;strong&gt;BatteryStatus&lt;/strong&gt;&lt;em&gt; &lt;/em&gt;reports 1, which means that &amp;ldquo;The battery is discharging&lt;em&gt;.&lt;/em&gt;&amp;rdquo; The other conditions are a bit more complicated. The following chart details the meaning of the status of the battery.&lt;/p&gt;
&lt;table cellspacing="0" cellpadding="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&lt;strong&gt;Value&lt;/strong&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;&lt;strong&gt;Meaning&lt;/strong&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&amp;nbsp;1&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;The battery is discharging.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&amp;nbsp;2&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;The system has access to AC so no battery is being discharged. However, the battery is not necessarily charging.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&amp;nbsp;3&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Fully Charged&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&amp;nbsp;4&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Low&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&amp;nbsp;5&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Critical&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&amp;nbsp;6&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Charging&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&amp;nbsp;7&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Charging and High&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&amp;nbsp;8&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Charging and Low&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&amp;nbsp;9&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Charging and Critical&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&amp;nbsp;10&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Undefined&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;&amp;nbsp;11&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;p&gt;Partially Charged&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For my purpose, I use the value like a Boolean&amp;mdash;1 means &amp;rdquo;on battery,&amp;rdquo; everything else means &amp;ldquo;plugged in&amp;rdquo; (at least for my script). Here is how I obtain the battery status.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;(Get-CimInstance win32_battery).batterystatus&lt;/p&gt;
&lt;h2&gt;Set the appropriate power plan&lt;/h2&gt;
&lt;p&gt;To set the power plan on my laptop, I use the Win32_PowerPlan WMI class (see yesterday&amp;rsquo;s article) and I call the &lt;strong&gt;Activate&lt;/strong&gt; method. All I really need to do is to add a bit of logic, then retrieve the appropriate power plan, and activate it. I decided, right now, that I will use &lt;strong&gt;Power Saver&lt;/strong&gt;&lt;em&gt; &lt;/em&gt;if the battery is discharging (1), &lt;strong&gt;High Performance&lt;/strong&gt;&lt;em&gt; &lt;/em&gt;if the battery is fully charged (3) and &lt;strong&gt;Balanced&lt;/strong&gt;, if the battery is any other status. The script is a simple If / ElseIF / Else type of construction. Here is the code.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;SetPowerSaverPlan.ps1&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;If ((Get-CimInstance win32_battery).batterystatus -eq 1)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; $p = Get-CimInstance -Name root\cimv2\power -Class win32_PowerPlan `&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; -Filter &amp;quot;ElementName = &amp;#39;Power Saver&amp;#39;&amp;quot;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Invoke-CimMethod -InputObject $p -MethodName Activate }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Elseif ((Get-CimInstance win32_battery).batterystatus -eq 3)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; $p = Get-CimInstance -Name root\cimv2\power -Class win32_PowerPlan `&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; -Filter &amp;quot;ElementName = &amp;#39;High performance&amp;#39;&amp;quot;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Invoke-CimMethod -InputObject $p -MethodName Activate }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Else&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;{&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; $p = Get-CimInstance -Name root\cimv2\power -Class win32_PowerPlan `&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; -Filter &amp;quot;ElementName = &amp;#39;Balanced&amp;#39;&amp;quot;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Invoke-CimMethod -InputObject $p -MethodName Activate }&lt;/p&gt;
&lt;p&gt;What I do not know, yet, is how often the script will select &lt;strong&gt;High Performance&lt;/strong&gt;. This is because, with the Windows Battery Conditioning technology, the battery does not always fully charge. At times, for example, on my laptop, the battery stops charging at 98 percent or so&amp;mdash;and I do not know if THAT condition reports as fully charged (3).&lt;em&gt; &lt;/em&gt;Therefore, after a bit of testing, I may eliminate the ElseIf condition, and do a simple If / Else and use the Else condition to set the full power plan.&lt;/p&gt;
&lt;p&gt;If I want to check to see what power plan gets applied as a result of the above script, I can do a simple query to check for the active power plan, as shown here.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Get-CimInstance -Name root\cimv2\power -Class win32_PowerPlan&amp;nbsp; -Filter &amp;quot;isactive = true&amp;quot; |&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; Select-Object elementname&lt;/p&gt;
&lt;p&gt;Well, that is about it for now. We have a lot of stuff to do and to see here in Oslo before the user group meeting this evening.&lt;/p&gt;
&lt;p&gt;Join me tomorrow when I will talk about changing the power plan on servers running Windows Server 2008&amp;nbsp;R2 and Windows Server&amp;nbsp;2012.&lt;/p&gt;
&lt;p&gt;I invite you to follow me on &lt;a href="http://bit.ly/scriptingguystwitter" target="_blank"&gt;Twitter&lt;/a&gt; and &lt;a href="http://bit.ly/scriptingguysfacebook" target="_blank"&gt;Facebook&lt;/a&gt;. If you have any questions, send email to me at &lt;a href="mailto:scripter@microsoft.com" target="_blank"&gt;scripter@microsoft.com&lt;/a&gt;, or post your questions on the &lt;a href="http://bit.ly/scriptingforum" target="_blank"&gt;Official Scripting Guys Forum&lt;/a&gt;. See you tomorrow. Until then, peace.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Ed Wilson, Microsoft Scripting Guy&lt;/strong&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3534750" width="1" height="1" alt="" /&gt;</description></item><item><title>PowerShell Community and the Windows System Administration Tool</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2012/01/06/powershell-community-and-the-windows-system-administration-tool.aspx</link><pubDate>Fri, 06 Jan 2012 06:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:13902</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: See how guest blogger, Rich Prescott, leveraged the Windows PowerShell community as he built his popular ArPosh Client System Administration tool.&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. We are really starting the new year off correctly. We have another very strong guest blogger today. Rich Prescott, is currently working as an infrastructure architect and Windows engineer at a large media company, with his main areas of focus on automation and Active Directory.&amp;nbsp;The automation responsibilities allow him to work with a wide-range of technologies including virtualization, storage, and monitoring.&amp;nbsp;He started learning Windows PowerShell in 2009 while he was working as a desktop engineer, and he is the lead scripting guy for his organization.&amp;nbsp;He is also a moderator on the &lt;a href="http://social.technet.microsoft.com/Forums/en-US/ITCG/threads" target="_blank"&gt;Official Scripting Guys Forum&lt;/a&gt;&lt;span style="text-decoration:underline;"&gt;,&lt;/span&gt; and was recently rewarded as a Microsoft Community Contributor.&lt;/p&gt;
&lt;p&gt;Blog: &lt;a href="http://blogs.technet.com/controlpanel/blogs/posteditor.aspx/blog.RichPrescott.com"&gt;Engineering Efficiency: Scripts, Tools, and Software New in the IT World&lt;/a&gt;&amp;nbsp;&lt;br /&gt; Twitter: &lt;a href="http://mce_host/controlpanel/blogs/posteditor.aspx/@Rich_Prescott"&gt;@Rich_Prescott&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Take it away Rich&amp;hellip;&lt;/p&gt;
&lt;p&gt;When I first joined the IT world, I was working at the Help desk for a large company. Being new to IT and troubleshooting, I always wondered why there was no single tool for troubleshooting remote computers. I would receive a call about a computer being slow, and I would have to go through four tools to try to diagnose the issue. I began searching for an easy solution, and that is when a coworker introduced me to Windows PowerShell. After reading blog posts from &lt;a href="http://www.scriptingguys.com/blog" target="_blank"&gt;Hey, Scripting Guy!&lt;/a&gt; and the &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/tags/scripting+wife/" target="_blank"&gt;Scripting Wife&lt;/a&gt;, I was writing basic scripts to gather the information that I needed for troubleshooting. This is an example of a basic script I wrote back then.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$PC = &amp;ldquo;PC01&amp;rdquo;&lt;br /&gt; Get-WmiObject Win32_OperatingSystem &amp;ndash;ComputerName $PC&lt;br /&gt; Get-WmiObject Win32_StartupCommand &amp;ndash;ComputerName $PC&lt;br /&gt; Get-WmiObject Win32_Process &amp;ndash;ComputerName $PC&lt;/p&gt;
&lt;p&gt;After the underlying issue was targeted, I needed a way to remediate the issue, such as removing a hung process. This was possible remotely by querying the Win32_Process class on a remote computer, filtering for the process that was causing an issue, and invoking the &lt;b&gt;Terminate&lt;/b&gt; method. Here is an example of using the &lt;b&gt;Terminate&lt;/b&gt; method to stop a process on a remote computer.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;(Get-WmiObject Win32_Process &amp;ndash;ComputerName $PC |&lt;br /&gt; Where-Object {$_.Name &amp;ndash;eq &amp;ldquo;HungProcessName&amp;rdquo;}).Terminate()&lt;/p&gt;
&lt;p&gt;At last, I was able to efficiently troubleshoot issues remotely and even resolve some of them without ever having to leave my desk. As I became more familiar with Windows PowerShell, I thought, &amp;ldquo;Wouldn&amp;rsquo;t it be cool if I could share the efficacy of Windows PowerShell with others, even if they don&amp;rsquo;t know any scripting?&amp;rdquo; After a few months of researching, scripting, and testing GUI creation with Windows PowerShell, the &lt;a href="http://gallery.technet.microsoft.com/a5aff367-7b47-4b50-a2ef-20dcb4bb6d64" target="_blank"&gt;Arposh Client System Administration tool&lt;/a&gt; (ACSA) was released.&lt;/p&gt;
&lt;p&gt;As with any technology that you learn rapidly, when you look back on what you were doing a year ago, you think to yourself, &amp;ldquo;What was I thinking when I wrote that? I could write that in half the code and make it twice as fast.&amp;rdquo; So I set out to find resources to help me rebuild the script from scratch, and I used this opportunity to remove some of the prerequisites, make it compatible with servers, and improve the overall user experience.&lt;/p&gt;
&lt;h3&gt;PowerShellGroup - #PowerShell chat room&lt;/h3&gt;
&lt;p&gt;&lt;br /&gt; One of the advantages of using Internet Relay Chat (IRC) is that there are chat rooms for almost any topic you can think of and when you are learning a new technology, having a live discussion can be really helpful. While revamping the ACSA tool, one of the user-experience features that I wanted to add was to give the user the ability to decide which feature sets to use through a configuration file.&lt;/p&gt;
&lt;p&gt;I joined the #PowerShell chat room on &lt;a href="http://powershellgroup.org/virtual/live" target="_blank"&gt;PowerShellGroup.org&lt;/a&gt;, and I asked about an easy way to give users configuration options. Jaykul, a Windows PowerShell MVP, responded with a way to read settings from an XML file. By using the following XML code and three lines of Windows PowerShell, a user is able to set a default domain to connect to when using the GUI. To have the GUI use the current domain of the logged on user, simply update the &lt;b&gt;Enabled&lt;/b&gt; option of the default domain to &amp;ldquo;False&amp;rdquo; in the XML configuration file.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; standalone=&amp;quot;no&amp;quot;?&amp;gt;&lt;br /&gt; &amp;nbsp;&amp;lt;Domain Default=&amp;quot;LDAP://DC=RU,DC=lab&amp;quot; Enabled=&amp;quot;True&amp;quot;/&amp;gt;&lt;/p&gt;
&lt;p&gt;In the first line of code, we use &lt;b&gt;Get-Content&lt;/b&gt; on the XML configuration file and specify that it is XML code by using [XML]. We then check to see if the default domain option is enabled, and if so, we set the &lt;b&gt;Domain&lt;/b&gt; variable to what is specified in the XML. If the option is disabled, the GUI sets the &lt;b&gt;Domain&lt;/b&gt; variable to the currently logged on domain.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;[XML]$XML = Get-Content &amp;ldquo;AWSA.Options.xml&amp;rdquo;&lt;br /&gt; &amp;nbsp;if($XML.Domain.Enabled &amp;ndash;eq $True){$Domain = $XML.Domain.Default}&lt;br /&gt; &amp;nbsp;else{$Domain = ([DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()).Name}&lt;/p&gt;
&lt;h3&gt;TechNet Wiki&lt;/h3&gt;
&lt;p&gt;My next task was to make the GUI easy to use, and this meant removing any unnecessary pre-requisites included in the original release. My first stop was the &lt;a href="http://social.technet.microsoft.com/wiki/" target="_blank"&gt;TechNet Wiki&lt;/a&gt; to find a way to query Active Directory for computers without the need to import a Windows PowerShell module that was not freely available on all systems. After a quick search, I landed on a wiki contribution from Richard Mueller, another MVP, for &lt;a href="http://social.technet.microsoft.com/wiki/contents/articles/5392.aspx" target="_blank"&gt;ADSI searches&lt;/a&gt;, which showed me the syntax necessary to build my custom function.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;function Get-RPADComputer{&lt;br /&gt; &amp;nbsp; if($ComputerName -match &amp;quot;.&amp;quot;){$ComputerName = $ComputerName.Split(&amp;#39;.&amp;#39;)[0]}&lt;br /&gt; &amp;nbsp; $searcher=[adsisearcher]&amp;quot;(&amp;amp;(objectClass=computer)(name=$ComputerName*))&amp;quot;&lt;br /&gt; &amp;nbsp; $Properties = $XML.Options.Search.Property&lt;br /&gt; &amp;nbsp; $searcher.PropertiesToLoad.AddRange($Properties) &lt;br /&gt; &amp;nbsp;&amp;nbsp;$searcher.FindAll()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;This function checks the &lt;i&gt;$ComputerName &lt;/i&gt;parameter that is specified in the textbox of the GUI, and if a fully qualified domain name (FQDN) is specified, it translates it to a short name. It then creates a query that will search for any computers that match the new &lt;i&gt;$ComputerName&lt;/i&gt; variable. The third line reads a list of properties that the user specifies in the XML settings file and adds them to the list of properties to load. The final line of the function executes the query and returns the results.&lt;/p&gt;
&lt;h3&gt;TechNet forums&lt;/h3&gt;
&lt;p&gt;&lt;br /&gt; After adding in the ability to set a default domain when launching the GUI, the user needed a way to change domains without having to edit the XML file and relaunch the script. I was not familiar enough with the ADSI scripting techniques that I found on the TechNet Wiki, and I decided to head over to the &lt;a href="http://social.technet.microsoft.com/Forums/en-us/ITCG/threads" target="_blank"&gt;Official Scripting Guys Forum&lt;/a&gt; on the &lt;a href="http://social.technet.microsoft.com/Forums/en-us/categories/" target="_blank"&gt;TechNet Forums&lt;/a&gt; and ask for some assistance.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/5ff7b8c0-9c32-44a3-8cc9-8859cd3dc691/" target="_blank"&gt;I posted my question&lt;/a&gt; with some examples of the input and output that I wanted, and within four hours, I received multiple responses from the community. And what do you know&amp;mdash;Richard Mueller again came to the rescue with a way to prompt for a domain and then convert the response into the LDAP path for that domain. By slightly tweaking his code, I was able to add the ability to search alternate domains to my custom Active Directory computer search function.&lt;/p&gt;
&lt;h3&gt;TechNet ScriptCenter&lt;/h3&gt;
&lt;p&gt;&lt;br /&gt; There are many new features in this update of the GUI, but I want to highlight one that many administrators will find very useful and sigh at the mention of: local administrator rights. Every system administrator has received a request along the lines of, &amp;ldquo;I need to install XYZ software right now!&amp;rdquo; or &amp;ldquo;I am using VPN from home, and I need to add a local printer.&amp;rdquo; One way to get around this (not always the best way) is to grant the user temporary local administrator rights. To find out how to do this the Windows PowerShell way, I headed over to the &lt;a href="http://gallery.technet.microsoft.com/scriptcenter/" target="_blank"&gt;TechNet ScriptCenter Repository&lt;/a&gt; to search for some examples.&lt;/p&gt;
&lt;p&gt;Using the &lt;b&gt;Categories&lt;/b&gt; listing in the left pane, I drilled down into &lt;b&gt;Local Account Management&lt;/b&gt;, and I immediately saw what I was looking for: &lt;a href="http://gallery.technet.microsoft.com/scriptcenter/f75801e7-169a-4737-952c-1341abea5823" target="_blank"&gt;Local User Management Module&lt;/a&gt;. I clicked through to the details page and looked through the included functions. I was in luck! By using ADSI code in the &lt;b&gt;Set-LocalGroup&lt;/b&gt; function, I morphed it into my own function as shown here.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;Function Add-LocalAdmin {&lt;br /&gt; &amp;nbsp;&amp;nbsp;[System.Reflection.Assembly]::LoadWithPartialName(&amp;#39;Microsoft.VisualBasic&amp;#39;) | Out-Null&lt;br /&gt; &amp;nbsp;&amp;nbsp;$Input = [Microsoft.VisualBasic.Interaction]::InputBox(&amp;quot;Enter a username to add (Domain\Username)&amp;quot;, &amp;quot;Add Local Admin&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt; &amp;nbsp;&amp;nbsp;$Group = [ADSI](&amp;quot;WinNT://&amp;quot; + $ComputerName + &amp;quot;/Administrators, group&amp;quot;)&lt;br /&gt; &amp;nbsp;&amp;nbsp;$Group.Add(&amp;quot;WinNT://&amp;quot; +$Input.Replace(&amp;lsquo;\&amp;rsquo;,&amp;rsquo;/&amp;rsquo;)&lt;br /&gt; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;The first line of the function loads the Visual Basic assembly; this allows me to create a custom input box, which prompts the user for the username to add to the local administrators group and then stores it in the &lt;b&gt;$Input&lt;/b&gt; variable. The function then binds to the Administrators group on the remote computer using ADSI. Now we call the &lt;b&gt;Add&lt;/b&gt; method of ADSI to add the desired user account to the administrators group. But there is a snag, the username is specified as Domain\Username, whereas ADSI requires a forward slash. To get around this, we use the &lt;b&gt;Replace&lt;/b&gt; method to turn the back slash into a forward slash.&lt;/p&gt;
&lt;h3&gt;Arposh Windows System Administration tool&lt;/h3&gt;
&lt;p&gt;&lt;br /&gt; Whether you are new to Windows PowerShell and only need a simple script to get you going or you are a Windows PowerShell guru and need a nudge in the right direction, there are numerous resources for everyone. Thanks to all of these resources, I was able to take a simple GUI that I created for myself to make tasks easier and improve it enough to where the Windows PowerShell community would also find it useful. Without further ado, here is the &lt;a href="http://gallery.technet.microsoft.com/Arposh-Windows-System-a1beb102" target="_blank"&gt;Arposh Windows System Administration tool&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/3666.hsg_2D00_1_2D00_6_2D00_12_2D00_1.jpg"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/3666.hsg_2D00_1_2D00_6_2D00_12_2D00_1.jpg" alt="Image of Arposh" title="Image of Arposh" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;~Rich&lt;/p&gt;
&lt;p&gt;I invite you to follow me on &lt;a href="http://bit.ly/scriptingguystwitter" target="_blank"&gt;Twitter&lt;/a&gt; and &lt;a href="http://bit.ly/scriptingguysfacebook" target="_blank"&gt;Facebook&lt;/a&gt;. If you have any questions, send email to me at &lt;a href="mailto:scripter@microsoft.com" target="_blank"&gt;scripter@microsoft.com&lt;/a&gt;, or post your questions on the &lt;a href="http://bit.ly/scriptingforum" target="_blank"&gt;Official Scripting Guys Forum&lt;/a&gt;. See you tomorrow. Until then, peace.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3473467" width="1" height="1" alt="" /&gt;</description></item><item><title>Use PowerShell to Find and Uninstall Software</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2011/12/14/use-powershell-to-find-and-uninstall-software.aspx</link><pubDate>Wed, 14 Dec 2011 06:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:13629</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: Learn how to use Windows PowerShell to get software installation locations, and to uninstall software from remote computers.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;img title="Hey, Scripting Guy! Question" border="0" alt="Hey, Scripting Guy! Question" align="left" src="http://img.microsoft.com/library/media/1033/technet/images/scriptcenter/qanda/q-sm.jpg" width="34" height="34" /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Hey, Scripting Guy! We have a dumb application that we have to use at work. The company has released a new version of this application, and I am trying to write a Windows PowerShell script to uninstall the old application&amp;mdash;the problem is that I need to find the application first. I tried looking in the registry, but the install key is empty&amp;hellip;figures. Like I said, this is a really dumb application. I read the &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2011/11/13/use-powershell-to-quickly-find-installed-software.aspx" target="_blank"&gt;guest blog written by Marc Carter&lt;/a&gt; about problems using the &lt;b&gt;Win32_Product &lt;/b&gt;WMI class, but it looks like I am going to be stuck using this anyway. The problem is that it is really slow. Is there any way to speed this thing up? I have to query over a thousand computers, and in our testing, this query takes nearly five minutes to complete&amp;mdash;that would be three and a half days for only one query.&lt;/p&gt;
&lt;p&gt;&amp;mdash;BT&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;span&gt;&lt;img title="Hey, Scripting Guy! Answer" border="0" alt="Hey, Scripting Guy! Answer" align="left" src="http://img.microsoft.com/library/media/1033/technet/images/scriptcenter/qanda/a-sm.jpg" width="34" height="34" /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp;Hello BT,&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. The Scripting Wife and I were in Texas for the Corpus Christi Windows PowerShell User Group meeting when Marc Carter told me about the problem with the MSI installer reconfiguring applications when the &lt;b&gt;Win32_Product &lt;/b&gt;WMI class is queried. I immediately encouraged him to write a guest blog about this issue.&lt;/p&gt;
&lt;p&gt;BT, there is a way to use the &lt;b&gt;Win32_Product &lt;/b&gt;WMI class in a more efficient manner. It relies on using the [WMI] type accelerator, instead of doing a generic WMI query. The problem is that the [WMI] type accelerator returns a specific instance of a WMI class. To connect to a specific instance, I must use the &lt;b&gt;Key&lt;/b&gt; property of a WMI class.&lt;/p&gt;
&lt;p&gt;I can use the &lt;b&gt;Get-WMIKey&lt;/b&gt; function from my &lt;a href="http://gallery.technet.microsoft.com/scriptcenter/WMI-Helper-Module-for-90e4f22e" target="_blank"&gt;HSGWMImoduleV6 module&lt;/a&gt;. In the following code, I first import my HSGWMImoduleV6 module, and then I use the &lt;b&gt;Get-WMIKey&lt;/b&gt; function to return the key to the &lt;b&gt;Win32_Product &lt;/b&gt;WMI class. The commands and the output from the commands are shown here.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS C:\&amp;gt; Import-Module hsg*6&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS C:\&amp;gt; Get-WmiKey win32_product&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;IdentifyingNumber&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Name&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Version&lt;/p&gt;
&lt;p&gt;The &lt;b&gt;Key&lt;/b&gt; property for &lt;b&gt;Win32_Product&lt;/b&gt; is a composite key comprised of &lt;b&gt;IdentifyingNumber&lt;/b&gt;, &lt;b&gt;Name&lt;/b&gt;, and &lt;b&gt;Version&lt;/b&gt;. The easy way to get this information is to use the &lt;b&gt;Get-WmiObject&lt;/b&gt; cmdlet to query for the information. I only need to do this once, and I will have the three pieces of information. A table is a nice way to display the information. In the code shown here, I use the &lt;b&gt;Get-WmiObject&lt;/b&gt; cmdlet (&lt;b&gt;gwmi&lt;/b&gt; is an alias) to return product information, and then I pipe the management objects to the &lt;b&gt;Format-Table&lt;/b&gt; (&lt;b&gt;ft&lt;/b&gt; is an alias) cmdlet for display.&lt;/p&gt;
&lt;p&gt;gwmi win32_product | ft name, version, ident*&lt;/p&gt;
&lt;p&gt;In the image that follows, I import the HSGWMIModuleV6 module, use the &lt;b&gt;Get-WMIKey&lt;/b&gt; function to retrieve the &lt;b&gt;Key&lt;/b&gt; property of the &lt;b&gt;Win32_Product &lt;/b&gt;WMI class. I then use the &lt;b&gt;Get-WmiObject&lt;/b&gt; cmdlet (&lt;b&gt;gwmi&lt;/b&gt; is an alias) to query the &lt;b&gt;Win32_Product&lt;/b&gt; WMI class, and I output the management objects to a table via the &lt;b&gt;Format-Table&lt;/b&gt; (&lt;b&gt;ft&lt;/b&gt; is alias) cmdlet. The following image displays the commands and the output from the commands.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/0160.HSG_2D00_12_2D00_14_2D00_11_2D00_01.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/0160.HSG_2D00_12_2D00_14_2D00_11_2D00_01.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;BT, you may ask, &amp;ldquo;What about Marc Carter&amp;rsquo;s warning about using the &lt;b&gt;Win32_Product &lt;/b&gt;WMI class? &amp;ldquo; Well as seen in the results from querying the event log, it is a concern. Shortly after querying the &lt;b&gt;Win32_Product &lt;/b&gt;WMI&lt;b&gt; &lt;/b&gt;class, I used the &lt;b&gt;Get-EventLog&lt;/b&gt; cmdlet to query the application log for MSIInstaller events. The following image shows massive product reconfiguring going on.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8446.HSG_2D00_12_2D00_14_2D00_11_2D00_02.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8446.HSG_2D00_12_2D00_14_2D00_11_2D00_02.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The query to return the three parts of the composite key only needs to run once; the values do not change. It is also possible to use the &lt;b&gt;Get-WmiObject&lt;/b&gt; cmdlet and a &lt;i&gt;filter&lt;/i&gt; to improve the performance of the command a little bit. The nice thing about this command is that it returns the information that is required by the [WMI] type accelerator. The command and associated output are shown here.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS C:\&amp;gt; gwmi win32_product -filter &amp;quot;Name LIKE &amp;#39;%Silverlight%&amp;#39;&amp;quot;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;IdentifyingNumber : {89F4137D-6C26-4A84-BDB8-2E5A4BB71E00}&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Microsoft Silverlight&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Vendor&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Microsoft Corporation&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Version&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 4.0.60831.0&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Caption&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Microsoft Silverlight&lt;/p&gt;
&lt;p&gt;When I have the three pieces of information (the &lt;b&gt;IdentifyingNumber&lt;/b&gt;, the &lt;b&gt;Name&lt;/b&gt;, and the &lt;b&gt;Version&lt;/b&gt;), it is time to create the key. This is where quite a bit of experimentation could be required. I have to use the back tick (grave) character to escape inside quotation marks. I have to escape the quotation mark and the opening curly bracket for the &lt;b&gt;IdentifyingNumber &lt;/b&gt;property. I also have to escape the closing curly bracket and the closing quotation mark. I then have to escape the quotation marks that surround Microsoft Silverlight, in addition to the quotation marks for the &lt;b&gt;Version&lt;/b&gt; property. There are also two quotation marks at the end of the &lt;b&gt;ClassKey&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;Here is the key I derived for Microsoft Silverlight on my computer. (This is a single line command. A space between Microsoft and Silverlight exists, but other than that, there are no spaces).&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$classKey=&amp;quot;IdentifyingNumber=`&amp;quot;`{89F4137D-6C26-4A84-BDB8-2E5A4BB71E00`}`&amp;quot;,Name=`&amp;quot;Microsoft Silverlight`&amp;quot;,version=`&amp;quot;4.0.60831.0`&amp;quot;&amp;quot;&lt;/p&gt;
&lt;p&gt;The reason for all the escaping in the &lt;b&gt;ClassKey&lt;/b&gt;, is that WMI expects the quotation marks and the curly brackets in the key itself. To see what WMI expects to receive via the command, I use the Windows Management Instrumentation Tester (&lt;b&gt;WbemTest&lt;/b&gt;) command, and I view the instances of the class. The following image illustrates the instances of &lt;b&gt;Win32_Product&lt;/b&gt; on my computer.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/0246.HSG_2D00_12_2D00_14_2D00_11_2D00_03.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/0246.HSG_2D00_12_2D00_14_2D00_11_2D00_03.png" alt="Image of query results" title="Image of query results" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;When I have the &lt;b&gt;ClassKey&lt;/b&gt;, I can use the [WMI] type accelerator to connect to the specific software package (Microsoft Silverlight in this example). In fact, using the [WMI] type accelerator is very easy. Here is the command. (The command is [WMI], the class name, and the key).&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;[wmi]&amp;quot;Win32_Product.$classkey&amp;quot;&lt;/p&gt;
&lt;p&gt;I can also include the WMI namespace (really important if the class resides in a namespace other than the default root\cimv2). In the command that follows, notice that there is a backslash that precedes the word &lt;i&gt;root. &lt;/i&gt;One other thing to notice is that a colon separates the WMI namespace and the WMI class name.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;[wmi]&amp;quot;\root\cimv2:Win32_Product.$classkey&amp;quot;&lt;/p&gt;
&lt;p&gt;If I need to connect to a WMI class on a remote computer, I use a double backslash and the name of the computer, then the WMI namespace, the WMI class, and the WMI &lt;b&gt;ClassKey&lt;/b&gt;. The command that follows illustrates this.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;[wmi]\\remotehost\root\cimv2:Win32_Product.$classkey&lt;/p&gt;
&lt;p&gt;In the image that follows, I illustrate the different ways of querying WMI for Microsoft Silverlight software. I then compare the speed of using the &lt;b&gt;Get-WmiObject&lt;/b&gt; cmdlet against the speed of using the [WMI] type accelerator. As shown in the following image, the &lt;b&gt;Get-WmiObject&lt;/b&gt; cmdlet, using the &lt;i&gt;filter &lt;/i&gt;to find Microsoft Silverlight, takes over five seconds on my laptop. Using the [WMI] type accelerator takes less than one-half of a second. This is more than 10 times faster. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/4578.HSG_2D00_12_2D00_14_2D00_11_2D00_04.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/4578.HSG_2D00_12_2D00_14_2D00_11_2D00_04.png" alt="Image of results" title="Image of results" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;By the way, there was not much difference between using the &lt;i&gt;filter &lt;/i&gt;to look for Microsoft Silverlight or using the &lt;b&gt;Where-Object&lt;/b&gt;. In the following output, I use the &lt;b&gt;Measure-Object&lt;/b&gt; cmdlet to determine the performance of using the &lt;b&gt;Where-Object&lt;/b&gt; (the &lt;b&gt;?&lt;/b&gt; is an alias for &lt;b&gt;Where-Object&lt;/b&gt;).&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS C:\&amp;gt; measure-command {gwmi win32_product | ? {$_.name -match &amp;#39;silverlight&amp;#39;}}&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Days&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 0&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Hours&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 0&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Minutes&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 0&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Seconds&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 5&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Milliseconds&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 311&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Ticks&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 53112518&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;TotalDays&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 6.14728217592593E-05&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;TotalHours&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 0.00147534772222222&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;TotalMinutes&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 0.0885208633333333&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;TotalSeconds&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 5.3112518&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;TotalMilliseconds : 5311.2518&lt;/p&gt;
&lt;p&gt;If you suspect that the problem with the &lt;i&gt;filter &lt;/i&gt;is that I used the &lt;b&gt;like&lt;/b&gt; operator as opposed to the &lt;b&gt;equality&lt;/b&gt; operator, that is not the case. Here are the results from using the &lt;b&gt;equality&lt;/b&gt; operator.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS C:\&amp;gt; measure-command {gwmi win32_product | ? {$_.name -match &amp;#39;silverlight&amp;#39;}}&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Days&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 0&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Hours&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 0&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Minutes&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 0&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Seconds&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 5&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Milliseconds&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 311&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Ticks&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 53112518&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;TotalDays&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 6.14728217592593E-05&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;TotalHours&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 0.00147534772222222&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;TotalMinutes&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 0.0885208633333333&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;TotalSeconds&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;: 5.3112518&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;TotalMilliseconds : 5311.2518&lt;/p&gt;
&lt;p&gt;When using the [WMI] type accelerator, a complete instance of the WMI class instance returns. The properties and their associated values are shown in the following image. Notice two properties: the &lt;b&gt;__Path&lt;/b&gt; (that is, double underscore &lt;b&gt;Path&lt;/b&gt;) property is the key to the WMI class instance. The &lt;b&gt;InstallLocation&lt;/b&gt;&lt;i&gt; &lt;/i&gt;property points to the location where the software installs.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/3343.HSG_2D00_12_2D00_14_2D00_11_2D00_05.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/3343.HSG_2D00_12_2D00_14_2D00_11_2D00_05.png" alt="Image of results" title="Image of results" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;BT, you did not ask, but there is an &lt;b&gt;Uninstall&lt;/b&gt;&lt;i&gt; &lt;/i&gt;method available from the &lt;b&gt;Win32_Product&lt;/b&gt; WMI class. It appears only on instances of the class. Therefore, it is possible to uninstall software by using the command that is shown here. (If I want to uninstall from a large collection of servers, I use the &lt;i&gt;foreach &lt;/i&gt;statement ($servers is an array of server names).&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;foreach($server in $servers)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;{ ([wmi]&amp;quot;\\$server\root\cimv2:Win32_Product.$classKey&amp;quot;).uninstall() }&lt;/p&gt;
&lt;p&gt;BT, that is all there is to using the &lt;b&gt;Win32_Product&lt;/b&gt; WMI class to detect or to uninstall software. Join me tomorrow when I will have a guest blog written by Raymond Mitchel as he talks about Windows PowerShell and SharePoint.&lt;/p&gt;
&lt;p&gt;I invite you to follow me on &lt;a href="http://bit.ly/scriptingguystwitter" target="_blank"&gt;Twitter&lt;/a&gt; and &lt;a href="http://bit.ly/scriptingguysfacebook" target="_blank"&gt;Facebook&lt;/a&gt;. If you have any questions, send email to me at &lt;a href="mailto:scripter@microsoft.com" target="_blank"&gt;scripter@microsoft.com&lt;/a&gt;, or post your questions on the &lt;a href="http://bit.ly/scriptingforum" target="_blank"&gt;Official Scripting Guys Forum&lt;/a&gt;. See you tomorrow. Until then, peace.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3470425" width="1" height="1" alt="" /&gt;</description></item><item><title>Create a Custom Object from WMI by Using PowerShell</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2011/09/27/create-a-custom-object-from-wmi-by-using-powershell.aspx</link><pubDate>Tue, 27 Sep 2011 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:12519</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;: Create a custom object from WMI to display processor and operating system information using Windows PowerShell.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img title="Hey, Scripting Guy! Question" border="0" alt="Hey, Scripting Guy! Question" align="left" src="http://img.microsoft.com/library/media/1033/technet/images/scriptcenter/qanda/q-sm.jpg" width="34" height="34" /&gt;Hey, Scripting Guy! Your script &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2011/09/26/use-powershell-and-wmi-to-get-processor-information.aspx"&gt;yesterday&lt;/a&gt; was pretty cool. However, in addition to obtaining information about the processor, I also need to know operating system is 32-bit or 64-bit, the version of Windows that is installed, and the service pack that is installed. I hate to be picky, but this is the information I need in order to plan for our upgrade project.&lt;/p&gt;
&lt;p&gt;&amp;mdash;BB&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img title="Hey, Scripting Guy! Answer" border="0" alt="Hey, Scripting Guy! Answer" align="left" src="http://img.microsoft.com/library/media/1033/technet/images/scriptcenter/qanda/a-sm.jpg" width="34" height="34" /&gt;Hello BB,&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy Ed Wilson here. First, I need to apologize to the Scripting Wife. Yesterday was her birthday, and I did not mention it in the Hey, Scripting Guy! Blog. Sorry!&lt;/p&gt;
&lt;p&gt;Beyond the disappointed Scripting Wife, BB, I am glad you enjoyed yesterday&amp;rsquo;s article. It is one of those things that sort of gets out of control. I begin working on a script and keep adding to it. So I will simply continue adding to it for today.&lt;/p&gt;
&lt;p&gt;First, make sure you have the script from yesterday&amp;rsquo;s Hey Scripting Guy! Article. The script, as it stood at the end of yesterday, is shown here:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Import-Module ActiveDirectory&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$pingConfig = @{&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;quot;count&amp;quot; = 1&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;quot;bufferSize&amp;quot; = 15&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;quot;delay&amp;quot; = 1&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;quot;EA&amp;quot; = 0 }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$computer = $cn = $null&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$cred = Get-Credential&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;Get-ADComputer -filter * -Credential $cred |&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;ForEach-Object {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(Test-Connection -ComputerName $_.dnshostname @pingconfig)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { $computer += $_.dnshostname + &amp;quot;`r`n&amp;quot;} }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$computer = $computer -split &amp;quot;`r`n&amp;quot;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$property = &amp;quot;systemname&amp;quot;,&amp;quot;maxclockspeed&amp;quot;,&amp;quot;addressWidth&amp;quot;,&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;quot;numberOfCores&amp;quot;, &amp;quot;NumberOfLogicalProcessors&amp;quot;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;foreach($cn in $computer)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;{&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;if($cn -match $env:COMPUTERNAME)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; Get-WmiObject -class win32_processor -Property&amp;nbsp; $property |&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; Select-Object -Property $property }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;elseif($cn.Length -gt 0)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; Get-WmiObject -class win32_processor -Property $property -cn $cn -cred $cred |&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; &amp;nbsp;Select-Object -Property $property } }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now, let&amp;rsquo;s see if I can find the additional information you need for your upgrade project. Actually, it is pretty simple because everything you need is in the &lt;b&gt;Win32_OperatingSystem&lt;/b&gt; WMI class. The &lt;a href="http://msdn.microsoft.com/en-us/library/aa394239(VS.85).aspx"&gt;Win32_OperatingSystem WMI class is documented on MSDN&lt;/a&gt;, but the properties needed for today&amp;rsquo;s script are rather straightforward and do not need extensive documentation. A quick check of the &lt;b&gt;Win32_Operatingsystem&lt;/b&gt; WMI class reveals everything I need. The command I use to perform this check is shown here (&lt;b&gt;gwmi&lt;/b&gt; is an alias for &lt;b&gt;Get-WmiObject&lt;/b&gt; and &lt;b&gt;fl&lt;/b&gt; is alias for &lt;b&gt;Format-List&lt;/b&gt;):&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;gwmi win32_operatingsystem | fl *&lt;/p&gt;
&lt;p&gt;The command and associated output are shown in the following figure.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8863.hsg_2D00_9_2D00_27_2D00_11_2D00_01.png"&gt;&lt;img style="border:0px;" title="Image of command and associated output" alt="Image of command and associated output" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8863.hsg_2D00_9_2D00_27_2D00_11_2D00_01.png" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The revised script is named GetADComputersAndWMiProcessorAndOSInfo.ps1.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;GetADComputersAndWMiProcessorAndOSInfo&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Import-Module ActiveDirectory&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$pingConfig = @{&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;quot;count&amp;quot; = 1&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;quot;bufferSize&amp;quot; = 15&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;quot;delay&amp;quot; = 1&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;quot;EA&amp;quot; = 0 }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$computer = $cn = $null&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$cred = Get-Credential&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;Get-ADComputer -filter * -Credential $cred |&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;ForEach-Object {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(Test-Connection -ComputerName $_.dnshostname @pingconfig)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { $computer += $_.dnshostname + &amp;quot;`r`n&amp;quot;} }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$computer = $computer -split &amp;quot;`r`n&amp;quot;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$property = &amp;quot;systemname&amp;quot;,&amp;quot;maxclockspeed&amp;quot;,&amp;quot;addressWidth&amp;quot;,&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;quot;numberOfCores&amp;quot;, &amp;quot;NumberOfLogicalProcessors&amp;quot;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$osProperty = &amp;quot;Caption&amp;quot;, &amp;quot;OSArchitecture&amp;quot;,&amp;quot;ServicePackMajorVersion&amp;quot;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;foreach($cn in $computer)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;{&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;if($cn -match $env:COMPUTERNAME)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; $obj = Get-WmiObject -class win32_processor -Property&amp;nbsp; $property |&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Select-Object -Property $property&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; $os =&amp;nbsp; Get-WmiObject -class win32_OperatingSystem -Property&amp;nbsp; $osproperty |&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;Select-Object -Property $osproperty&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; } #end if&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;elseif($cn.Length -gt 0)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; $obj = Get-WmiObject -class win32_processor -Property $property -cn $cn -cred $cred |&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; Select-Object -Property $property&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; $os = Get-WmiObject -class win32_OperatingSystem -Property $osproperty -cn $cn -cred $cred |&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; Select-Object -Property $osproperty&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; } #end elseif&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; New-Object psobject -Property @{&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; &amp;quot;name&amp;quot; = $obj.systemname&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; &amp;quot;speed&amp;quot; = $obj.maxclockspeed&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; &amp;quot;addressWidth&amp;quot; = $obj.addressWidth&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; &amp;quot;numberCores&amp;quot; = $obj.numberOfCores&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; &amp;quot;numberLogicalProcessors&amp;quot; = $obj.NumberOfLogicalProcessors&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; &amp;quot;OSname&amp;quot; = $os.Caption&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; &amp;quot;OSArchitecture&amp;quot; = $os.OSArchitecture&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; &amp;quot;ServicePack&amp;quot; = $os.ServicePackMajorVersion&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; #$os&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;} #END FOREACH&lt;/p&gt;
&lt;p&gt;When the script runs, the first thing that happens is a credential dialog box displays. This is because I request credentials for connection to remote systems. The credentials are not used to connect to the local computer. The credential dialog box is shown in the following figure.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/0726.hsg_2D00_9_2D00_27_2D00_11_2D00_02.png"&gt;&lt;img style="border:0px;" title="Image of credential dialog box" alt="Image of credential dialog box" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/0726.hsg_2D00_9_2D00_27_2D00_11_2D00_02.png" width="429" height="316" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I added an array of properties to store the operating system information:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$osProperty = &amp;quot;Caption&amp;quot;, &amp;quot;OSArchitecture&amp;quot;,&amp;quot;ServicePackMajorVersion&amp;quot;&lt;/p&gt;
&lt;p&gt;This change is shown in the following figure.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/7633.hsg_2D00_9_2D00_27_2D00_11_2D00_03.png"&gt;&lt;img style="border:0px;" title="Image of the change" alt="Image of the change" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/7633.hsg_2D00_9_2D00_27_2D00_11_2D00_03.png" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In addition, I changed the portion of the script inside the &lt;b&gt;Foreach&lt;/b&gt; loop so that I am storing the &lt;b&gt;Processor&lt;/b&gt; object instead of directly emitting. I also added a WMI query to retrieve the operating system information. The revised section is shown here:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;foreach($cn in $computer)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;{&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;if($cn -match $env:COMPUTERNAME)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; $obj = Get-WmiObject -class win32_processor -Property&amp;nbsp; $property |&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Select-Object -Property $property&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; $os =&amp;nbsp; Get-WmiObject -class win32_OperatingSystem -Property&amp;nbsp; $osproperty |&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Select-Object -Property $osproperty&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; } #end if&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;elseif($cn.Length -gt 0)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; $obj = Get-WmiObject -class win32_processor -Property $property -cn $cn -cred $cred |&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; Select-Object -Property $property&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; $os = Get-WmiObject -class win32_OperatingSystem -Property $osproperty -cn $cn -cred $cred |&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; Select-Object -Property $osproperty&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp; } #end elseif&lt;/p&gt;
&lt;p&gt;This portion of the revised code is shown in the following figure.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8585.hsg_2D00_9_2D00_27_2D00_11_2D00_04.png"&gt;&lt;img style="border:0px;" title="Image of this portion of revised code" alt="Image of this portion of revised code" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8585.hsg_2D00_9_2D00_27_2D00_11_2D00_04.png" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;To make it easier to work with the output, I decided to return a custom object. This object contains information from both WMI classes. In addition, I changed some of the column headings to make it easier to read. This section of the script that creates the new object is shown here:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;New-Object psobject -Property @{&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; &amp;quot;name&amp;quot; = $obj.systemname&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; &amp;quot;speed&amp;quot; = $obj.maxclockspeed&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; &amp;quot;addressWidth&amp;quot; = $obj.addressWidth&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; &amp;quot;numberCores&amp;quot; = $obj.numberOfCores&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; &amp;quot;numberLogicalProcessors&amp;quot; = $obj.NumberOfLogicalProcessors&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; &amp;quot;OSname&amp;quot; = $os.Caption&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; &amp;quot;OSArchitecture&amp;quot; = $os.OSArchitecture&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; &amp;quot;ServicePack&amp;quot; = $os.ServicePackMajorVersion&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp; } #end new object&lt;/p&gt;
&lt;p&gt;This portion of the new code is shown in the following figure.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/3108.hsg_2D00_9_2D00_27_2D00_11_2D00_05.png"&gt;&lt;img style="border:0px;" title="Image of this portion of new code" alt="Image of this portion of new code" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/3108.hsg_2D00_9_2D00_27_2D00_11_2D00_05.png" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;When the script runs, the following output is displayed.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/5657.hsg_2D00_9_2D00_27_2D00_11_2D00_06.png"&gt;&lt;img style="border:0px;" title="Image of output displayed when script is run" alt="Image of output displayed when script is run" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/5657.hsg_2D00_9_2D00_27_2D00_11_2D00_06.png" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;BB, that is all there is to using Windows PowerShell to query for both processor and operating system information.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I invite you to follow me on &lt;a href="http://bit.ly/scriptingguystwitter" target="_blank"&gt;Twitter&lt;/a&gt; and &lt;a href="http://bit.ly/scriptingguysfacebook"&gt;Facebook&lt;/a&gt;. If you have any questions, send email to me at &lt;a href="mailto:scripter@microsoft.com" target="_blank"&gt;scripter@microsoft.com&lt;/a&gt;, or post your questions on the &lt;a href="http://bit.ly/scriptingforum" target="_blank"&gt;Official Scripting Guys Forum&lt;/a&gt;. See you tomorrow. Until then, peace.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3455615" width="1" height="1" alt="" /&gt;</description></item></channel></rss>