<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-1555090447439276032</atom:id><lastBuildDate>Fri, 01 Nov 2024 09:50:30 +0000</lastBuildDate><category>Powershell</category><category>group policy</category><category>Utility</category><category>PDFCreator</category><category>Server 2008</category><category>Advanced Functions</category><category>CSE</category><category>Error Handling</category><category>Exchange</category><category>GPO</category><category>GUI</category><category>VMWare</category><category>WinRM</category><category>XML</category><category>alias</category><category>backup</category><category>backup-gpo</category><category>credSSP</category><category>discoverability</category><title>Output Redirection</title><description></description><link>http://outputredirection.blogspot.com/</link><managingEditor>noreply@blogger.com (v(^_^)v - Clint)</managingEditor><generator>Blogger</generator><openSearch:totalResults>31</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1555090447439276032.post-990259413936512427</guid><pubDate>Tue, 27 Dec 2011 18:37:00 +0000</pubDate><atom:updated>2011-12-29T11:09:36.947-08:00</atom:updated><title>Frivolous PowerShell</title><description>PowerShell is great for Windows enterprise heavy lifting and automation.&amp;nbsp; It&#39;s also great for answering some of life&#39;s smaller, and perhaps more important, questions like &quot;When will this 18 gigabyte download be done?&quot;.&amp;nbsp; Granted, most browsers and download managers have a time estimate easily available.&amp;nbsp; However, I found myself with a large download and no built in time estimate the other day.&amp;nbsp; I don&#39;t know about you, but I&#39;m not very good at figuring out how many hours a multiple gigabyte download will take at 475Kb/sec in my head.&amp;nbsp; Turns out it&#39;s pretty simple in PowerShell:
&lt;br /&gt;
&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;
&lt;br /&gt;
PS&amp;gt;(get-date).addseconds(16.8GB/475KB)&lt;/div&gt;
&lt;br /&gt;
Then again, when it told me that my download wouldn&#39;t finish until after midnight - I just went to bed!</description><link>http://outputredirection.blogspot.com/2011/12/frivolous-powershell.html</link><author>noreply@blogger.com (v(^_^)v - Clint)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1555090447439276032.post-5232800839455836904</guid><pubDate>Fri, 12 Aug 2011 16:26:00 +0000</pubDate><atom:updated>2011-08-13T11:50:24.487-07:00</atom:updated><title>This Should NOT Happen (Exchange 2010)</title><description>Since I can&#39;t find a connect site to submit feedback to:&lt;br /&gt;
&lt;br /&gt;
Get-Mailbox -Identity $null&lt;br /&gt;
&lt;redacted&gt;&lt;br /&gt;
WARNING: By default, only the first 1000 items are returned. Use the ResultSize parameter to specify the number of items returned. To&lt;br /&gt;
return all items, specify &quot;-ResultSize Unlimited&quot;. Be aware that, depending on the actual number of items, returning all items can&lt;br /&gt;
take a long time and consume a large amount of memory. Also, we don&#39;t recommend storing the results in a variable. Instead, pipe the&lt;br /&gt;
results to another task or script to perform batch changes.&lt;br /&gt;
&lt;br /&gt;
...Nope, looks like I&#39;m wrong on this one.  For the sake of consistency this is exactly what *should* happen.</description><link>http://outputredirection.blogspot.com/2011/08/this-should-not-happen-exchange-2010.html</link><author>noreply@blogger.com (v(^_^)v - Clint)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1555090447439276032.post-8629607056047836369</guid><pubDate>Thu, 10 Mar 2011 19:34:00 +0000</pubDate><atom:updated>2011-03-10T11:36:47.477-08:00</atom:updated><title>RAID-5 is the Devil</title><description>&lt;p&gt;And I’ll tell you why.&amp;#160; But first, the TLDR takeaway:&amp;#160; &lt;strong&gt;If you have a storage array of anything over a terabyte or two DO NOT use RAID-5, use RAID-6 or something with superior fault tolerance&lt;/strong&gt;.&amp;#160; If you remember anything from this post remember that or you may find yourself in the position I’m in currently, lost data and all.&lt;/p&gt;&lt;p&gt;It really comes down to one little performance specification that until now I hadn’t ever really noticed: “Unrecoverable read errors”.&amp;#160; For the latest Seagate home drive that statistic is 1 in 10&lt;sup&gt;14&lt;/sup&gt;, for a standard SATA Enterprise class drive that number is an order of magnitude better, 1 in 10&lt;sup&gt;15&lt;/sup&gt;.&amp;#160; Remember those numbers and now read &lt;a href=&quot;http://queue.acm.org/detail.cfm?id=1670144&quot;&gt;this excellent article&lt;/a&gt; as well as &lt;a href=&quot;http://media.netapp.com/documents/netapp-raid-dp.pdf&quot;&gt;one of the referenced white papers&lt;/a&gt; from NetApp, and perhaps finish off with &lt;a href=&quot;http://storagemojo.com/2010/02/27/does-raid-6-stops-working-in-2019/&quot;&gt;this StorageMojo post&lt;/a&gt;.&amp;#160; &lt;/p&gt;&lt;p&gt;See the problem now?&amp;#160; My backup server sure did when it ran afoul of a double drive failure.&amp;#160; Perhaps it was just bad jujus, but my 6x1TB drive array (with hot spare) had a drive fail – and hit “Unrecoverable read error” while reconstructing the data to the hot spare.&amp;#160; So now I’m working at evacuating the existing data and restoring from backups.&amp;#160; To save yourself that trouble it’s worth remembering:&lt;/p&gt;&lt;p&gt;&lt;em&gt;&lt;font size=&quot;3&quot;&gt;&lt;strong&gt;For large arrays, RAID-5 is the devil.&lt;/strong&gt;&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;</description><link>http://outputredirection.blogspot.com/2011/03/raid-5-is-devil.html</link><author>noreply@blogger.com (v(^_^)v - Clint)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1555090447439276032.post-185056897474580023</guid><pubDate>Fri, 04 Mar 2011 23:13:00 +0000</pubDate><atom:updated>2011-03-04T15:13:27.670-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Powershell</category><category domain="http://www.blogger.com/atom/ns#">VMWare</category><title>Monitoring/Logging Concurrent VDI Sessions with Host CPU &amp;amp; RAM utilization</title><description>&lt;p&gt;So we have spent the past few months sizing, installing, adjusting, and growing a proof-of-concept implementation of VMWare’s virtual desktop product, View 4.5.&amp;#160; One question that was kind of fun to develop an easily digestible solution for was, “How can we keep track of and trend how the VDI solution is being used?”&amp;#160; Naturally, I turned to my technical multitool of choice, PowerShell, for a solution.&lt;/p&gt;&lt;p&gt;As a simple logging and review tool we decided that we would like to know how many Remote Sessions were currently active, what the average CPU % utilization was, and the average % RAM utilization was.&amp;#160; I added Disk and Network stats to the logs as well.&amp;#160; For the Remote Session stats we have to use the ‘View PowerCLI’ PowerShell Snap-in, “VMware.View.Broker”.&amp;#160; The last time I checked it was not available as a standalone installer nor was part of the standard VMWare PowerCLI distributable.&amp;#160; Because of this we either have to run our powershell script locally on our view manager server, or use PowerShell sessions and remoting.&amp;#160; In the interest of simplicity I chose to run the script locally on our View Manager server.&amp;#160; For the Host(s) CPU, RAM, Disk, &amp;amp; Network utilization we’ll use the &lt;a href=&quot;http://communities.vmware.com/community/vmtn/vsphere/automationtools/powercli?source=web&amp;amp;cd=1&amp;amp;ved=0CBwQFjAA&amp;amp;url=http://www.vmware.com/go/powercli&amp;amp;rct=j&amp;amp;q=powercli&amp;amp;ei=bjVxTcqtKpDSsAPZ4IXYCw&amp;amp;usg=AFQjCNFddkbqT43ZTSqBGo7UBPzAQnwPPg&quot;&gt;standard PowerCLI distributable&lt;/a&gt;.&amp;#160; For historical purposes I log the information to a simple CSV file, and we use PowerGadgets for a “live” view of the statistics.&lt;/p&gt;&lt;p&gt;Okay, let’s check the script out.&amp;#160; First things first, we make sure that the required snap-ins are available.&lt;/p&gt;&lt;pre&gt;&lt;span style=&quot;color: #008000&quot;&gt;# Add the necessary snapins, throwing terminating errors 
# should they not be available on the machine
&lt;/span&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;-not&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #5f9ea0&quot;&gt;get-pssnapin&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #000080&quot;&gt;$_&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8b4513&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;-eq&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #800000&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color: #800000&quot;&gt;VMware.View.Broker&lt;/span&gt;&lt;span style=&quot;color: #800000&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; }))
{
  &lt;/span&gt;&lt;span style=&quot;color: #5f9ea0&quot;&gt;add-pssnapin&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8b4513&quot;&gt;VMware.View.Broker&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #5f9ea0&quot;&gt;-ErrorAction&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;Stop&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;
}
&lt;/span&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;-not&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #5f9ea0&quot;&gt;get-pssnapin&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; { &lt;/span&gt;&lt;span style=&quot;color: #000080&quot;&gt;$_&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8b4513&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;-eq&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #800000&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color: #800000&quot;&gt;VMware.VimAutomation.Core&lt;/span&gt;&lt;span style=&quot;color: #800000&quot;&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; }))
{
  &lt;/span&gt;&lt;span style=&quot;color: #5f9ea0&quot;&gt;Add-PSSnapin&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #8b4513&quot;&gt;VMware.VimAutomation.Core&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #5f9ea0&quot;&gt;-ErrorAction&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;Stop&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;
}&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;Easy enough.&amp;#160; Next let’s get some script variables setup with some explanations along the way.&lt;/p&gt;&lt;pre&gt;&lt;span style=&quot;color: #800080&quot;&gt;$today&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #5f9ea0&quot;&gt;Get-Date&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: #800080&quot;&gt;$logPath&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #800000&quot;&gt;&amp;quot;C:\ViewStatLogs&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: #800080&quot;&gt;$logName&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: #800000&quot;&gt;&amp;quot;{0}.log&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;-f&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #800080&quot;&gt;$today&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8b4513&quot;&gt;ToString&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #800000&quot;&gt;&amp;quot;yyyy-MM-dd&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;)
&lt;/span&gt;&lt;span style=&quot;color: #800080&quot;&gt;$logexists&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #5f9ea0&quot;&gt;test-path&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #008000; text-decoration: underline&quot;&gt;$logPath\$logname&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;Here we’re just setting up our logfiles.&amp;#160; For the script to function, we’ll need to make sure that the $logpath already exists.&amp;#160; For the sake of space I setup the directory as compressed as well.&amp;#160; Next we define the name of the logfile which will define how our logs are broken up.&amp;#160; Currently mine are broken up by the day, though I’m thinking that it may be better to do them some other way…time will tell.&amp;#160; $logexists should be pretty self-explanatory.&amp;#160; Now for some variables that are a bit more interesting.&lt;/p&gt;&lt;pre&gt;&lt;span style=&quot;color: #800080&quot;&gt;$dnsDomain&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #800000&quot;&gt;&amp;quot;mydomain.net&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: #800080&quot;&gt;$vCenterServer&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #800000&quot;&gt;&amp;quot;vCenter&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: #800080&quot;&gt;$vSphereHosts&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #800000&quot;&gt;&amp;quot;ESXi03&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;)
&lt;/span&gt;&lt;span style=&quot;color: #800080&quot;&gt;$statsToGet&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;(  &lt;/span&gt;&lt;span style=&quot;color: #800000&quot;&gt;&amp;quot;cpu.usage.average&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;
                  &lt;/span&gt;&lt;span style=&quot;color: #800000&quot;&gt;&amp;quot;mem.usage.average&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;
                  &lt;/span&gt;&lt;span style=&quot;color: #800000&quot;&gt;&amp;quot;disk.usage.average&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;
                  &lt;/span&gt;&lt;span style=&quot;color: #800000&quot;&gt;&amp;quot;net.usage.average&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;
               )&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;So here we have $dnsDomain, which I use because I’m lazy and hate typing FQDNs all the time.&amp;#160; Next is the vCenter Server that is used to manage the host/hosts that compose our View cluster.&amp;#160; We’ll connect to this server to get the CPU/RAM/Disk/Network statistics.&amp;#160; We’re still in “growing proof-of-concept” phase so we only have a single vSphere host running in our View cluster which is specified in $vSphereHosts.&amp;#160; Next is an array of the statistics that we want to gather for each vSphere Host, in this case the average usage for cpu, mem, disk, and net(work).&amp;#160; For more information on the statistics that are available, consult the help for the &lt;a href=&quot;http://www.vmware.com/support/developer/PowerCLI/PowerCLI41/html/Get-Stat.html&quot;&gt;Get-Stat&lt;/a&gt; &amp;amp; &lt;a href=&quot;http://www.vmware.com/support/developer/PowerCLI/PowerCLI41/html/Get-StatType.html&quot;&gt;Get-StatType&lt;/a&gt; cmdlets for the VMware.VimAutomation.Core snap-in.&amp;#160; Next let’s setup the header for our CSV logfile, and create the file if it doesn’t already exist.&lt;/p&gt;&lt;pre&gt;&lt;span style=&quot;color: #008000&quot;&gt;# Define the log header
&lt;/span&gt;&lt;span style=&quot;color: #800080&quot;&gt;$logHeader&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #800000&quot;&gt;&amp;quot;Time,SessionCount&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: #008000&quot;&gt;# Alter the header for each host/stat combo
&lt;/span&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;foreach&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #800080&quot;&gt;$vsh&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #800080&quot;&gt;$vSphereHosts&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;)
{
  &lt;/span&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;foreach&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #800080&quot;&gt;$stat&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #800080&quot;&gt;$statsToGet&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;)
  {
    &lt;/span&gt;&lt;span style=&quot;color: #800080&quot;&gt;$logHeader&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #800000&quot;&gt;&amp;quot;,{0}.{1}&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;-f&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #800080&quot;&gt;$vsh&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #800080&quot;&gt;$stat&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;
  }
}

&lt;/span&gt;&lt;span style=&quot;color: #008000&quot;&gt;# Create the log file if it doesn&#39;t exist
&lt;/span&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;-not&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #800080&quot;&gt;$logexists&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;)
{
  &lt;/span&gt;&lt;span style=&quot;color: #5f9ea0&quot;&gt;Out-File&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #5f9ea0&quot;&gt;-FilePath&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #008000; text-decoration: underline&quot;&gt;$logPath\$logName&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; `
&lt;/span&gt;&lt;span style=&quot;color: #5f9ea0&quot;&gt;-inputobject&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #800080&quot;&gt;$logHeader&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #5f9ea0&quot;&gt;-force&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #5f9ea0&quot;&gt;-encoding&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;ASCII&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;
}&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;Pretty straightforward stuff here as well.&amp;#160; We setup the header with timestamp &amp;amp; sessioncount, then append each chosen statistic for each vSphere host.&amp;#160; Now we’ll get our stats and write the information out.&lt;/p&gt;&lt;pre&gt;&lt;span style=&quot;color: #800080&quot;&gt;$rSessions&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #5f9ea0&quot;&gt;get-remotesession&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;)
&lt;/span&gt;&lt;span style=&quot;color: #800080&quot;&gt;$outString&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #800000&quot;&gt;&amp;quot;{0:HH:mm},{1}&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;-f&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #5f9ea0&quot;&gt;get-date&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #800080&quot;&gt;$rSessions&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8b4513&quot;&gt;count&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;

&lt;/span&gt;&lt;span style=&quot;color: #5f9ea0&quot;&gt;Connect-VIServer&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #800080&quot;&gt;$vCenterServer&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;foreach&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #800080&quot;&gt;$vsh&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #800080&quot;&gt;$vSphereHosts&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;)
{
  &lt;/span&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;foreach&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #800080&quot;&gt;$stat&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #800080&quot;&gt;$statsToGet&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;)
  {
    [&lt;/span&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #800080&quot;&gt;$statVal&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #5f9ea0&quot;&gt;Get-Stat&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #5f9ea0&quot;&gt;-Entity&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #800000&quot;&gt;&amp;quot;$vsh.$dnsDomain&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #5f9ea0&quot;&gt;`&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;
      &lt;/span&gt;&lt;span style=&quot;color: #5f9ea0&quot;&gt;-Start&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #800080&quot;&gt;$today&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #8b4513&quot;&gt;ToShortDateString&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color: #5f9ea0&quot;&gt;-IntervalMins&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #5f9ea0&quot;&gt;-Stat&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #800080&quot;&gt;$stat&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #5f9ea0&quot;&gt;`&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;
      &lt;/span&gt;&lt;span style=&quot;color: #5f9ea0&quot;&gt;Select-Object&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #5f9ea0&quot;&gt;-ExpandProperty&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #5f9ea0&quot;&gt;-First&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;
    &lt;/span&gt;&lt;span style=&quot;color: #800080&quot;&gt;$outString&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #800000&quot;&gt;&amp;quot;,$statVal&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;
  }
}

&lt;/span&gt;&lt;span style=&quot;color: #5f9ea0&quot;&gt;Out-File&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #5f9ea0&quot;&gt;-FilePath&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #008000; text-decoration: underline&quot;&gt;$logPath\$logName&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; `
&lt;/span&gt;&lt;span style=&quot;color: #5f9ea0&quot;&gt;-inputobject&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #800080&quot;&gt;$outString&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #5f9ea0&quot;&gt;-append&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #5f9ea0&quot;&gt;-encoding&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;ASCII&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;
&lt;/span&gt;&lt;span style=&quot;color: #008000&quot;&gt;# Close all vSphere PowerCLI server connections
&lt;/span&gt;&lt;span style=&quot;color: #5f9ea0&quot;&gt;Disconnect-VIServer&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #5f9ea0&quot;&gt;-Force&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: #ff0000&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;Confirm&lt;/span&gt;&lt;span style=&quot;color: #000000&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0000ff&quot;&gt;$false&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;Code very similar to setting up the header for the log.&amp;#160; We grab all the remote sessions our View manager is tracking into an array, then use the count (length) of the array for the information we log.&amp;#160; Next we connect to our vCenter server and for each vSphere Host we gather the last recorded 5 minute interval value of each chosen statistic.&amp;#160; There are only so many interval values available by default, and you can find our what you have available by running the &lt;a href=&quot;http://www.vmware.com/support/developer/PowerCLI/PowerCLI41/html/Get-StatInterval.html&quot;&gt;Get-StatInterval&lt;/a&gt; cmdlet.&amp;#160; Next we write out the completed string to the logfile.&amp;#160; Lastly we disconnect the VIServer session.&lt;/p&gt;&lt;p&gt;The last bit in this formula is setting up the schedule.&amp;#160; You’ll get the most detailed information by setting up a scheduled task that runs on 5 minute intervals that match the intervals that you see when running Get-StatInterval and Get-Stat from the console.&amp;#160; That said, I only run mine every 10 minutes – we’re really just looking for an overview.&amp;#160; One thing to make sure is that the task is setup to run as a user that has the correct permissions to connect and gather statistics from your vCenter server, otherwise the whole script will just hang!&lt;/p&gt;&lt;p&gt;So, great – we can log, but how to make a nice pretty picture out of it?&amp;#160; That’s a question with lots of different answers.&amp;#160; There’s a lot of different ways to visualize statistic data, you probably have your favorite, and the details will depend on your hosts and the statistics you want to track, so I’ll just share a quick pic of what we use to keep an eye on things using &lt;a href=&quot;http://www.softwarefx.com/sfxSqlProducts/powergadgets/&quot;&gt;PowerGadgets&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqa6Z_yCNpOTxS8SBkfCIEjlRIISlt_Zzlva5l0jUgM2v6Vr0M9eT_RQ0wvMIzKf0M40hHfDvF_rLk852mHtx3FX1LRFV7O0Yyy7tzazEXkoxwwN5vjqLAbhIblJ60uvcmVEzd3jKlNdx0/s1600-h/image%5B2%5D.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTVZVuZikAG78OhLyT7NdB7yh9oAjfvSbaaDJoKeM25i8gzSbn5Luoo7ugtKk_xKDSmltcY_SGvpsHkvkk0slkLz2tOhXBk8JhcmjUGTOmEDYvtCUqW4fdZezdElG9Q4SpJ8eYVy2e2zjQ/?imgmax=800&quot; width=&quot;244&quot; height=&quot;139&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Hope that can help or inspire somebody out there, Happy Friday!&lt;/p&gt;</description><link>http://outputredirection.blogspot.com/2011/03/monitoringlogging-concurrent-vdi.html</link><author>noreply@blogger.com (v(^_^)v - Clint)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTVZVuZikAG78OhLyT7NdB7yh9oAjfvSbaaDJoKeM25i8gzSbn5Luoo7ugtKk_xKDSmltcY_SGvpsHkvkk0slkLz2tOhXBk8JhcmjUGTOmEDYvtCUqW4fdZezdElG9Q4SpJ8eYVy2e2zjQ/s72-c?imgmax=800" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1555090447439276032.post-4399279898654546330</guid><pubDate>Wed, 22 Dec 2010 20:05:00 +0000</pubDate><atom:updated>2010-12-22T12:05:35.379-08:00</atom:updated><title>A diversion</title><description>Gonna take a break from the System Admin stuff for a second to share the best darn game deal out there right now.  The &lt;a href=&quot;http://www.humblebundle.com&quot;&gt;Humble Indie Bundle&lt;/a&gt;.  Pay what you want for 6 fun games, or pay more than the average ($7.44 when I wrote this) and get last years bundle as well!  World of Goo is easily worth the price of admission.  And you can activate all the games on Steam, or just download them and keep the DRM free installers.  The Humble Indie Bundle, it&#39;s awesome.</description><link>http://outputredirection.blogspot.com/2010/12/diversion.html</link><author>noreply@blogger.com (v(^_^)v - Clint)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1555090447439276032.post-1606055310533877646</guid><pubDate>Thu, 16 Dec 2010 17:24:00 +0000</pubDate><atom:updated>2010-12-16T09:24:01.813-08:00</atom:updated><title>Reset Live@Edu passwords with a simple Windows Form</title><description>&lt;p&gt;Once again, I’ve gone what seems like ages without taking the time to share.&amp;#160; We’ve been so busy with implementing Microsoft’s Live@Edu service as well as piloting VMWare’s View I just haven’t taken the time.&amp;#160; In any case, here’s a little form I put together in Primalforms that connects to Live@Edu, and allows you to search for your students and change their passwords easily.&amp;#160; You can embed credentials, but by default the script will prompt for credentials each time the script is run.&amp;#160; The code is below, I think I&#39;ve decided to go with poshcode.org for pasting code and what not.&lt;/p&gt;&lt;script type=&quot;text/javascript&quot; src=&quot;http://PoshCode.org/embed/2411&quot;&gt;&lt;/script&gt;</description><link>http://outputredirection.blogspot.com/2010/12/reset-liveedu-passwords-with-simple.html</link><author>noreply@blogger.com (v(^_^)v - Clint)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1555090447439276032.post-8529368459604109707</guid><pubDate>Fri, 01 Oct 2010 20:49:00 +0000</pubDate><atom:updated>2010-10-01T21:23:39.785-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Advanced Functions</category><category domain="http://www.blogger.com/atom/ns#">Powershell</category><title>When is an empty string not an empty string?</title><description>Man, it’s been a long time since I took the time to post something for which I apologize.&amp;nbsp; It’s been a busy few months.&amp;nbsp; But today we’ll get back into the swing of things with a mystery to solve.&amp;nbsp; We start with a distilled version of an advanced function a friend of mine was working with:&lt;br /&gt;
&lt;pre&gt;&lt;span style=&quot;color: blue;&quot;&gt;function&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: cadetblue;&quot;&gt;Test-Mystery&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;
{
    [&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;CmdletBinding&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;()]
    &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;param&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;
    (
        [&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;ValidateNotNullOrEmpty&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;()]
        &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;$paramOne&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;
    )
    
    &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;$paramOne&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;
    &lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;$paramOne&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: saddlebrown;&quot;&gt;length&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;
}
&lt;/span&gt;&lt;/pre&gt;&lt;span style=&quot;font-family: Verdana;&quot;&gt;Pretty straightforward advanced function stuff, we have a parameter that we need to validate.  It can be anything it wants as long as it’s not null, and is not an empty string.  If we test this, we’ll find that it works.  Mostly.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS &amp;gt; $x = &quot;HELLO WORLD&quot;     &lt;br /&gt;
PS &amp;gt; Test-Mystery -paramOne $x      &lt;br /&gt;
HELLO WORLD      &lt;br /&gt;
11&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS &amp;gt; $x = &quot;&quot;     &lt;br /&gt;
PS &amp;gt; Test-Mystery -paramOne $x      &lt;br /&gt;
Test-Mystery : Cannot validate argument on parameter &#39;paramOne&#39;. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.      &lt;br /&gt;
At line:2 char:23      &lt;br /&gt;
+ Test-Mystery -paramOne &amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;nbsp; $x      &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; + CategoryInfo&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : InvalidData: (:) [Test-Mystery], ParameterBindingValidationException      &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; + FullyQualifiedErrorId : ParameterArgumentValidationError,Test-Mystery&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Okay, that works as expected.&amp;nbsp; But let’s try that with input from the Read-Host cmdlet.&amp;nbsp; First we’ll enter in a string, then we’ll just hit Enter to return nothing (in theory).&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS &amp;gt; $x = Read-Host &quot;Test &quot;     &lt;br /&gt;
PS &amp;gt; Test-Mystery -paramOne $x      &lt;br /&gt;
Test: HELLO WORLD      &lt;br /&gt;
HELLO WORLD      &lt;br /&gt;
11&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS &amp;gt; $x = Read-Host &quot;Test &quot;     &lt;br /&gt;
PS &amp;gt; Test-Mystery -paramOne $x      &lt;br /&gt;
Test: &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;0&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Uhh….what?&amp;nbsp; That totally should have exploded, and yet it doesn’t.&amp;nbsp; Adding to the mystery is that the variable being assigned the return value from Read-Host is indeed a [System.String] variable and it is assigned the value of ‘’ (or an empty string).&amp;nbsp; At least that’s what PSDebug tells us:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS &amp;gt; $x = read-host &#39;test &#39;     &lt;br /&gt;
DEBUG:&amp;nbsp;&amp;nbsp;&amp;nbsp; 1+ $x = &amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;nbsp; read-host &#39;test &#39;      &lt;br /&gt;
test :      &lt;br /&gt;
DEBUG:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ! SET $x = &#39;&#39;.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS &amp;gt; $x.gettype()&amp;nbsp;     &lt;br /&gt;
IsPublic IsSerial Name&amp;nbsp;&amp;nbsp;&amp;nbsp; BaseType      &lt;br /&gt;
-------- -------- ------&amp;nbsp; --------      &lt;br /&gt;
True&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; True&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; String&amp;nbsp; System.Object&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;&lt;br /&gt;
PS &amp;gt; $x –eq “”     &lt;br /&gt;
True&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
And so thus is given to us the mystery:&amp;nbsp; when is an empty string not an empty string?&amp;nbsp; Evidently, when it’s created by Read-Host.&amp;nbsp; But, thankfully there is a fairly straight forward solution.&amp;nbsp; We strongly type the variable being assigned the output from Read-Host.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS &amp;gt; [string]$x = Read-Host &#39;Test &#39;     &lt;br /&gt;
Test :      &lt;br /&gt;
&lt;br /&gt;
PS &amp;gt; Test-Mystery $x      &lt;br /&gt;
Test-Mystery : Cannot validate argument on parameter &#39;paramOne&#39;. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.      &lt;br /&gt;
At line:2 char:13      &lt;br /&gt;
+ Test-Mystery &amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;nbsp; $x      &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; + CategoryInfo&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : InvalidData: (:) [Test-Mystery], ParameterBindingValidationException      &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; + FullyQualifiedErrorId : ParameterArgumentValidationError,Test-Mystery&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
I’ll pose this question on the &lt;a href=&quot;http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/threads&quot;&gt;PowerShell Technet Forums&lt;/a&gt;, and see if it this is ‘as designed’ or a genuine bug that we need to file on Connect.&amp;nbsp; Until then, case (almost) closed.</description><link>http://outputredirection.blogspot.com/2010/10/when-is-empty-string-not-empty-string.html</link><author>noreply@blogger.com (v(^_^)v - Clint)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1555090447439276032.post-1717347250108631084</guid><pubDate>Fri, 06 Aug 2010 14:44:00 +0000</pubDate><atom:updated>2010-08-06T07:44:56.238-07:00</atom:updated><title>Hey!  A send email cmdlet!</title><description>&lt;p&gt;So from the ‘oh my god I can’t believe I hadn’t found this earlier’ corner comes this:&amp;#160; PowerShell 2.0 ships with a new cmdlet called Send-MailMessage.&amp;#160; Why is this kinda sorta a big deal (at least to me, haha)?&amp;#160; PSCX will be deprecating the Send-SmtpMail cmdlet (that you may or may not have been using profusely, I know I have) in the next major revision.&amp;#160; So it’s time to start going through scripts and updating as needed.&amp;#160; Thankfully, the syntax is very similar.&amp;#160; The only changes that I found I needed to make were:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Change –AttachmentLiteralPath/-AttachmentPath to –Attachments&lt;/li&gt;    &lt;li&gt;Change –SmtpHost to –SmtpServer&lt;/li&gt; &lt;/ul&gt;  </description><link>http://outputredirection.blogspot.com/2010/08/hey-send-email-cmdlet.html</link><author>noreply@blogger.com (v(^_^)v - Clint)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1555090447439276032.post-4438243415907840257</guid><pubDate>Fri, 09 Jul 2010 15:40:00 +0000</pubDate><atom:updated>2010-07-09T08:40:50.393-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Exchange</category><category domain="http://www.blogger.com/atom/ns#">Powershell</category><title>Track Mass Exchange Mailbox Moves</title><description>&lt;p&gt;Moving a mailbox or two between Exchange databases and/or servers isn’t too hard to keep track of, but what if you’re moving 200?&amp;#160; Or 2000?&amp;#160; I came up with a little “one-liner” (can we really call a do loop a one-liner?) while migrating the bulk of our mailboxes from Exchange 2003 to 2010.&amp;#160; Hopefully you can use it to help you keep an eye on things too.&amp;#160; Here’s the script, first in a more traditional form, then in one-liner form for easy copy and paste into a shell session.&amp;#160; It’s a &lt;font face=&quot;Courier New&quot;&gt;do {} until ($false)&lt;/font&gt; loop so you have to Ctrl-C to break out of it.&lt;/p&gt;  &lt;h3&gt;&lt;/h3&gt;  &lt;h5&gt;Traditional Script Form&lt;/h5&gt;  &lt;p&gt;&lt;font face=&quot;Courier New&quot;&gt;do      &lt;br /&gt;{       &lt;br /&gt;&amp;#160; Clear-Host       &lt;br /&gt;&amp;#160; $mr = Get-MoveRequest&lt;/font&gt;&lt;font face=&quot;Courier New&quot;&gt;      &lt;br /&gt;&amp;#160; $mr | Group –Property Status | Select Name,Count | Format-Table –auto       &lt;br /&gt;&amp;#160; $mr | Where { $_.status –eq “InProgress” } | Select DisplayName,TotalMailboxSize,PercentComplete |       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Format-Table –auto       &lt;br /&gt;&amp;#160; Start-Sleep –seconds 60       &lt;br /&gt;} until ($false)&lt;/font&gt;&lt;/p&gt;  &lt;h5&gt;One-Liner Form&lt;/h5&gt;  &lt;p&gt;&lt;font face=&quot;Courier New&quot;&gt;do { cls ; $mr = Get-MoveRequest ; $mr | group status | select Name,Count | ft –auto ; $mr | ? { $_.status –eq “InProgress” } | select DisplayName,TotalMailboxSize,PercentComplete | ft –auto ; sleep –seconds 60 } until ($false)&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Hope you find that helpful!&lt;/p&gt;  </description><link>http://outputredirection.blogspot.com/2010/07/track-mass-exchange-mailbox-moves.html</link><author>noreply@blogger.com (v(^_^)v - Clint)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1555090447439276032.post-3454556198713113779</guid><pubDate>Mon, 14 Jun 2010 18:21:00 +0000</pubDate><atom:updated>2010-06-14T11:21:03.793-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">PDFCreator</category><category domain="http://www.blogger.com/atom/ns#">Server 2008</category><title>Updated PDFCreator post</title><description>I&#39;ve updated my post on running &lt;a href=&quot;http://outputredirection.blogspot.com/p/running-pdfcreator-as-service-on-server.html&quot;&gt;PDFCreator as a service&lt;/a&gt; to the latest version, 1.0.1. &amp;nbsp;It&#39;s also now a static page with a link at the top. &amp;nbsp;Enjoy!</description><link>http://outputredirection.blogspot.com/2010/06/updated-pdfcreator-post.html</link><author>noreply@blogger.com (v(^_^)v - Clint)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1555090447439276032.post-3413084262896441534</guid><pubDate>Wed, 09 Jun 2010 18:51:00 +0000</pubDate><atom:updated>2010-06-09T11:51:50.989-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">GUI</category><category domain="http://www.blogger.com/atom/ns#">Powershell</category><title>Things I learned from the Scripting Games 2010 #5</title><description>&lt;p&gt;In this final entry in the ‘Things I learned from the Scripting Games’ series, we’ll go over two different yet related bits of information.&amp;#160; The first is displaying balloon tips in the notification area (System Tray).&amp;#160; The second is displaying log-like feedback in a form generated in PowerShell.&amp;#160; Because they both relate to presenting information or feedback to the user, and because it’s been awhile since I posted anything…and because I promised someone I would try real hard to update my PDFCreator post this week, both subjects fit in one post today.&lt;/p&gt;  &lt;h3&gt;Balloon Tips&lt;/h3&gt;  &lt;p&gt;Often times when we need to present the user with information in a graphical way, the messagebox is sufficient.&amp;#160; However, because the messagebox is synchronous by default (that is, the script pauses execution until the messagebox is closed) and there isn’t an easy way to create an asynchronous messagebox, they don’t fit every scenario.&amp;#160; Sometimes we just want to display some information to the user and move on.&amp;#160; Enter balloon tips.&lt;/p&gt;  &lt;p&gt;For me, the most challenging part of making a balloon tip function wherever the script is running is the fact that it requires an icon.&amp;#160; How, exactly, is one to deliver an icon when (especially during the scripting games) all we have at our disposal is our PowerShell script file?&amp;#160; Let’s get our object setup and then we’ll answer that question.&amp;#160; First things first, load the forms assemblies:&lt;/p&gt;  &lt;p&gt;&lt;font face=&quot;Courier New&quot;&gt;[void][reflection.assembly]::Load(&amp;quot;System.Windows.Forms, `      &lt;br /&gt;&lt;/font&gt;&lt;font face=&quot;Courier New&quot;&gt;Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&amp;quot;)&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face=&quot;Ver&quot;&gt;Now we can create a new NotifyIcon object, and setup the text for the balloon tip:&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face=&quot;Courier New&quot;&gt;$notifyIcon = New-Object System.Windows.Forms.NotifyIcon      &lt;br /&gt;$notifyIcon.BalloonTipTitle = &amp;quot;Balloon Title&amp;quot;       &lt;br /&gt;$notifyIcon.BalloonTipText =&amp;#160; &amp;quot;Balloon Text&amp;quot;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;So, about that icon…turns out we can extract an icon from a file to use for the NotifyIcon object.&amp;#160; What file with icons should every relevant Windows system have?&amp;#160; Explorer.exe!&lt;/p&gt;  &lt;p&gt;&lt;font face=&quot;Courier New&quot;&gt;$notifyIcon.Icon = [System.drawing.icon]::ExtractAssociatedIcon(`      &lt;br /&gt;&amp;quot;$env:windir\explorer.exe&amp;quot;)&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;OK, so now we have everything setup, let’s display that balloon tip.&amp;#160; First we have to make the NotifyIcon visible, then we can display the balloon tip for the number of milliseconds we specify:&lt;/p&gt;  &lt;p&gt;&lt;font face=&quot;Courier New&quot;&gt;$notifyIcon.Visible = $true      &lt;br /&gt;$notifyIcon.ShowBalloonTip(3000)&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;There we go.&amp;#160; Presenting information to the user in a way that doesn’t pause script execution, done.&lt;/p&gt;  &lt;h3&gt;Display Scrolling Text in a Form Window&lt;/h3&gt;  &lt;p&gt;Coming up with a “how many times would I actually use this” example for this particular technique has proven difficult.&amp;#160; Maybe it’s because I don’t have much experience creating GUIs designed for end users.&amp;#160; But that said, a wall (or box) of scrolling text seems so deceptively simple that it took me a while to figure out how to accomplish the task.&lt;/p&gt;  &lt;p&gt;In advanced event 10 of the scripting games, one element was to present the user with progress of files being moved.&amp;#160; Instantly the picture of the nullsoft installer with it’s wall of text during the install sprung into my mind.&amp;#160; Achieving a similar effect isn’t too involved.&amp;#160; Here’s how we do it.&lt;/p&gt;  &lt;p&gt;First we’re going to setup 3 objects: a form, a textbox, and a button.&lt;/p&gt;  &lt;p&gt;&lt;font face=&quot;Courier New&quot;&gt;$form = new-object windows.forms.form      &lt;br /&gt;$form.Size = New-Object System.Drawing.Size(270,125) &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face=&quot;Courier New&quot;&gt;$txtBox = new-object windows.forms.textbox      &lt;br /&gt;$txtbox.Multiline = $true       &lt;br /&gt;$txtBox.WordWrap = $false       &lt;br /&gt;$txtBox.size = New-Object System.Drawing.Size(250,60)       &lt;br /&gt;$txtBox.ScrollBars = [System.Windows.Forms.ScrollBars]::Vertical &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face=&quot;Courier New&quot;&gt;$btn = new-object windows.forms.button      &lt;br /&gt;$btn.Location = new-object system.drawing.point(0,60)       &lt;br /&gt;$btn.Text = &amp;quot;Go!&amp;quot; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face=&quot;Courier New&quot;&gt;$form.Controls.Add($txtBox)      &lt;br /&gt;$form.Controls.Add($btn)&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;So we’ve assigned some size and location information to the controls and added the controls to the form, which is standard business so far.&amp;#160; Two properties of the textbox control are important for this particualr task: Multiline &amp;amp; ScrollBars.&amp;#160; We make sure to set the multiline property to true, and assign vertical scrollbars to the textbox.&amp;#160; I also like to disable wordwrap, but that’s just me.&lt;/p&gt;  &lt;p&gt;Next let’s setup the scriptblock that will run when we click the button:&lt;/p&gt;  &lt;p&gt;&lt;font face=&quot;Courier New&quot;&gt;$button_OnClick = {      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; 1..10 | % {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; $txtBox.Lines += $_       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; $txtBox.Select($txtBox.Text.Length, 0)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; $txtBox.ScrollToCaret()       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; $form.Update()       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; start-sleep 1       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;}       &lt;br /&gt;$btn.add_Click($button_OnClick)&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;So this is pretty simple.&amp;#160; We create a variable ($button_OnClick) and assign it a scriptblock in which we have a small loop.&amp;#160; We take the array created by the 1..10 range, and for each number we:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Add the number to the lines array property of the textbox &lt;/li&gt;    &lt;li&gt;Move the caret (cursor) to the last character in the textbox &lt;/li&gt;    &lt;li&gt;Scroll the textbox view to the caret &lt;/li&gt;    &lt;li&gt;Update the form &lt;/li&gt;    &lt;li&gt;Pause for a second &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;We add that scriptblock to the click event of the button by using the &lt;strong&gt;hidden&lt;/strong&gt; method add_Click($button_onClick).&amp;#160; As a side note in case you’re wondering, you use the –Force parameter of Get-Method to display hidden members.&amp;#160; Lastly let’s show the form:&lt;/p&gt;  &lt;p&gt;&lt;font face=&quot;Courier New&quot;&gt;$form.showdialog()&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Give that button a push!&amp;#160; Sure it’s a simplistic example, but it can be used to pretty good effect.&amp;#160; The $form.update() method caught me by surprise, probably because I’m pretty green with this GUI business.&amp;#160; To see what happens without calling the update method, comment out or delete the $form.Update() line and run $form.showdialog() again.&amp;#160; It’s like the whole form freezes while the loop runs!&amp;#160; Bad jujus.&lt;/p&gt;  &lt;p&gt;To see a more complete example you can check out my submission for Event 10 of the Scripting Games &lt;a href=&quot;http://2010sg.poshcode.org/code/1198.xhtml&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;  </description><link>http://outputredirection.blogspot.com/2010/06/things-i-learned-from-scripting-games_09.html</link><author>noreply@blogger.com (v(^_^)v - Clint)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1555090447439276032.post-6301788402784542000</guid><pubDate>Thu, 03 Jun 2010 05:00:00 +0000</pubDate><atom:updated>2010-06-02T22:00:38.876-07:00</atom:updated><title>Sorry for the reposts and instability</title><description>I&#39;ve been trying to troubleshoot an issue with the feed posting, and ended up deleting and reposting all the entries from the last month or so.&amp;nbsp; Sorry about that, hopefully I can get the feed &amp;amp; keyword business straightened out soon.&lt;br /&gt;
&lt;br /&gt;
Happy Wednesday!</description><link>http://outputredirection.blogspot.com/2010/06/sorry-for-reposts-and-instability.html</link><author>noreply@blogger.com (v(^_^)v - Clint)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1555090447439276032.post-5596349748019039561</guid><pubDate>Thu, 03 Jun 2010 04:35:00 +0000</pubDate><atom:updated>2010-06-02T21:35:54.161-07:00</atom:updated><title>Things I learned from the Scripting Games 2010 #4: Background Jobs</title><description>Okay, so background jobs themselves aren’t really the subject of this post.&amp;nbsp; But a handy function to make efficient use of them, and a &lt;strike&gt;quick&lt;/strike&gt; gotcha when using background jobs via Start-Job is.&amp;nbsp; Often times we need to execute the same code over and over, with one or two variations in each iteration.&amp;nbsp; That&#39;s what the function we’ll look at today is built to do.&amp;nbsp; The two mandatory parameters for this function, -scriptblock &amp;amp; -collection, really allow for some flexible backgrounding of similar tasks.&amp;nbsp; Take a moment and think, how many times have I needed to run the same or similar code against 10+ computers, users, files, directories, etc.&amp;nbsp; Probably doesn’t take too long before you have at least a few examples.&lt;br /&gt;
&lt;br /&gt;
Before we get into the function let’s address the gotcha.&amp;nbsp; I learned about a new parameter to Start-Job in Event #5 this year, ArgumentList.&amp;nbsp; If you look at the documentation on this parameter it is a little bit misleading.&amp;nbsp; I’ve filed a &lt;a href=&quot;https://connect.microsoft.com/PowerShell/feedback/details/563695/argumentlist-parameter-to-start-job-incomplete&quot;&gt;documentation bug on connect&lt;/a&gt; should you wish to vote for it.&amp;nbsp; The short of it is, even though the parameter help doesn’t mention that the ArgumentList parameter works with the ScriptBlock parameter, it does.&amp;nbsp; Which is pretty important.&amp;nbsp; To illustrate this, try the following:&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Create a variable      &lt;br /&gt;
$arr = 1..5 &lt;/li&gt;
&lt;li&gt;Start a background job that writes that variable to output      &lt;br /&gt;
$job = Start-Job –Scriptblock { Write-Output $arr } &lt;/li&gt;
&lt;li&gt;Receive the job      &lt;br /&gt;
Receive-Job $job &lt;/li&gt;
&lt;li&gt;Notice that there is no output, sadface. &lt;/li&gt;
&lt;/ol&gt;So, what happened?&amp;nbsp; Why don’t we have any output?&amp;nbsp; The answer lies in two bits of information.&amp;nbsp; The first we get from Get-Help about_jobs:&lt;br /&gt;
&lt;blockquote&gt;Important: &lt;b&gt;Background jobs that are started by using Start-Job or the AsJob parameter of Invoke-Command rely on the Windows PowerShell remoting infrastructure&lt;/b&gt;. To use these features, Windows PowerShell must be configured for remoting, even if the background job is run only on the local computer. For more information, see about_Remote_Requirements.&lt;/blockquote&gt;The second from Get-Help about_scopes:&lt;br /&gt;
&lt;blockquote&gt;Sessions: A session is an environment in which Windows PowerShell runs. When you create a session on a remote computer, Windows PowerShell establishes a persistent connection to the remote computer. The persistent connection lets you use the session for multiple related commands.&lt;br /&gt;
&lt;b&gt;Because a session is a contained environment, it has its own scope, but a session is not a child scope of the session in which is was created. The session starts with its own global scope&lt;/b&gt;. This scope is independent of the global scope of the session. You can create child scopes in the session. For example, you can run a script to create a child scope in a session.&lt;/blockquote&gt;Aha!&amp;nbsp; The variable scope is separate and distinct inside of the scriptblock that we pass to Start-Job.&amp;nbsp; So we use the ArgumentList parameter to get the information that we need to the scriptblock.&amp;nbsp; Let’s see that in action:&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Create a variable:      &lt;br /&gt;
$arr = 1..5 &lt;/li&gt;
&lt;li&gt;Start a background job, passing the variable as an argument:      &lt;br /&gt;
$job = Start-Job –Scriptblock { Write-Output $args } –ArgumentList $arr &lt;/li&gt;
&lt;li&gt;Receive the job      &lt;br /&gt;
Receive-Job $job &lt;/li&gt;
&lt;li&gt;Hey there’s our information! &lt;/li&gt;
&lt;/ol&gt;Sweet.&amp;nbsp; Hopefully that information will make working with background jobs a little easier for you.&amp;nbsp; Below is a function I wrote as part of my solution for Event 5.&amp;nbsp; It takes a scriptblock and a collection of items &amp;amp; iterates through the collection passing each item into the scriptblock.&amp;nbsp; By default it displays a progress bar to keep you abreast of the progress of the jobs.&amp;nbsp; For detailed information on how you can use it and examples, import the function into your powershell session and run ‘Get-Help Start-BackgroundJobs’&lt;br /&gt;
&lt;a href=&quot;http://sites.google.com/site/outputredirectionfilehosting/Start-BackgroundJobs.ps1?attredirects=0&amp;amp;d=1&quot;&gt;Get the function here&lt;/a&gt;.</description><link>http://outputredirection.blogspot.com/2010/06/things-i-learned-from-scripting-games_3703.html</link><author>noreply@blogger.com (v(^_^)v - Clint)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1555090447439276032.post-9071772907993144720</guid><pubDate>Thu, 03 Jun 2010 04:35:00 +0000</pubDate><atom:updated>2010-06-02T21:35:40.781-07:00</atom:updated><title>Things I learned from the Scripting Games 2010 #3: Test-Connection</title><description>Who knew there was a cmdlet designed just for testing remote connections?&amp;nbsp; Not me, at least until the scripting games this year.&amp;nbsp; For the past....forever, I&#39;ve been doing something like the following to test remote connections&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;$pingResults = Ping-Host -HostName $ComputerName -Count 2 -Quiet -ErrorAction SilentlyContinue&lt;br /&gt;
if ($pingResults.received -gt 0)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Do something&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;br /&gt;
}&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
And then I discovered test-connection! Now for simple quick tests we can just do:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;if (Test-Connection $ComputerName -count 2 -quiet)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Do something&lt;br /&gt;
}&lt;/div&gt;&lt;br /&gt;
For larger groups of computers I&#39;ll still use PSCX&#39;s Ping-Host cmdlet due it&#39;s ability to ping all specified hosts asynchronously and it&#39;s speed.&amp;nbsp; You&#39;ve &lt;a href=&quot;http://pscx.codeplex.com/&quot;&gt;updated to PSCX 2.0&lt;/a&gt;, right?&amp;nbsp; But Test-Connection is the right tool at the right price for quick connectivity checks.&amp;nbsp; Learn more about Test-Connection with Get-Help Test-Connection or on &lt;a href=&quot;http://technet.microsoft.com/en-us/library/dd315259.aspx&quot;&gt;Technet&lt;/a&gt;.</description><link>http://outputredirection.blogspot.com/2010/06/things-i-learned-from-scripting-games_02.html</link><author>noreply@blogger.com (v(^_^)v - Clint)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1555090447439276032.post-9031659853043356860</guid><pubDate>Thu, 03 Jun 2010 04:35:00 +0000</pubDate><atom:updated>2010-06-02T21:35:25.449-07:00</atom:updated><title>Things I learned from the Scripting Games 2010 #2: #Requires</title><description>&lt;div style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;So this post comes from the &quot;how embarrassing&quot; folder.&amp;nbsp; I&#39;ve been fiddling with and using PowerShell since it was the Monad beta, and until the scripting games I didn&#39;t know about&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt; #Requires&lt;/span&gt;.&amp;nbsp; &#39;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;#Requires&lt;/span&gt;&#39; is awesome.&amp;nbsp; You just stick it at or around the start of your script, and the magic happens.&amp;nbsp; There&#39;s a pretty good summary available in PowerShell if you type:&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;get-help about_Requires&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;But this all comes with a bit of a caveat, there isn&#39;t an option for &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;#Requires&lt;/span&gt; for those nifty new things called modules!&amp;nbsp; So we can &#39;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;#Requires -version 2&lt;/span&gt;&#39; to require PowerShell version 2, we can &#39;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;#Requires -PSSnapIn Quest.ActiveRoles.ADManagement&lt;/span&gt;&#39; to require the Quest AD snap-in....but we can&#39;t &#39;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;#Requires -Module grouppolicy&lt;/span&gt;&#39; to require a module.&amp;nbsp; Bummer.&amp;nbsp; So how can we require a module the &quot;hard&quot; way?&amp;nbsp; Here&#39;s one way:&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;pre class=&quot;PowerShellColorizedScript&quot;&gt;&lt;span style=&quot;color: darkblue;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color: blueviolet;&quot;&gt;Test-ModuleAvailability&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;[string]&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$modulename&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;[switch]&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$Import&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;            
&lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;            
    &lt;span style=&quot;color: darkgreen;&quot;&gt;# Check to see if our module is available&lt;/span&gt;            
    &lt;span style=&quot;color: teal;&quot;&gt;[System.Management.Automation.PSModuleInfo]&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$results&lt;/span&gt; &lt;span style=&quot;color: darkgrey;&quot;&gt;=&lt;/span&gt; `
          Get-Module &lt;span style=&quot;color: navy;&quot;&gt;-ListAvailable&lt;/span&gt; &lt;span style=&quot;color: darkgrey;&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; ?&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt; &lt;span style=&quot;color: orangered;&quot;&gt;$_&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;name&lt;/span&gt; &lt;span style=&quot;color: darkgrey;&quot;&gt;-ieq&lt;/span&gt; &lt;span style=&quot;color: orangered;&quot;&gt;$modulename&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;            
    &lt;span style=&quot;color: darkblue;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$results&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;            
    &lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;            
        &lt;span style=&quot;color: darkblue;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$Import&lt;/span&gt; &lt;span style=&quot;color: darkgrey;&quot;&gt;-and&lt;/span&gt; &lt;span style=&quot;color: orangered;&quot;&gt;$results&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;sessionState&lt;/span&gt; &lt;span style=&quot;color: darkgrey;&quot;&gt;-eq&lt;/span&gt; &lt;span style=&quot;color: orangered;&quot;&gt;$null&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;            
        &lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;            
            &lt;span style=&quot;color: darkgreen;&quot;&gt;#Import the module&lt;/span&gt;            
            &lt;span style=&quot;color: blue;&quot;&gt;Import-Module&lt;/span&gt; &lt;span style=&quot;color: orangered;&quot;&gt;$results&lt;/span&gt;            
        &lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;            
        &lt;span style=&quot;color: darkgreen;&quot;&gt;#Return true, the module is available&lt;/span&gt;            
        &lt;span style=&quot;color: orangered;&quot;&gt;$true&lt;/span&gt;            
    &lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;            
    &lt;span style=&quot;color: darkblue;&quot;&gt;else&lt;/span&gt;            
    &lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;            
        &lt;span style=&quot;color: darkgreen;&quot;&gt;#Return false, the module is not available&lt;/span&gt;            
        &lt;span style=&quot;color: orangered;&quot;&gt;$false&lt;/span&gt;            
    &lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;                
&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;
With this function we can easily test for a module&#39;s availability, load it if it we need to, and throw an error if $false is returned:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;PowerShellColorizedScript&quot;&gt;&lt;span style=&quot;color: darkblue;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;-not&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;$(&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;Test-ModuleAvailability&lt;/span&gt; &lt;span style=&quot;color: blueviolet;&quot;&gt;FileSystem&lt;/span&gt; &lt;span style=&quot;color: navy;&quot;&gt;-Import&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;            
&lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;            
    &lt;span style=&quot;color: darkblue;&quot;&gt;Throw&lt;/span&gt; &lt;span style=&quot;color: darkred;&quot;&gt;&quot;Could not find or load required Module FileSystem&quot;&lt;/span&gt;            
&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;
Not too hard, but maybe those PowerShell guys will hook us up with a beefed up #Requires statement later.&lt;br /&gt;
&lt;br /&gt;
Until tomorrow!</description><link>http://outputredirection.blogspot.com/2010/06/things-i-learned-from-scripting-games.html</link><author>noreply@blogger.com (v(^_^)v - Clint)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1555090447439276032.post-2219871830413280157</guid><pubDate>Thu, 03 Jun 2010 04:35:00 +0000</pubDate><atom:updated>2010-06-02T21:35:06.369-07:00</atom:updated><title>Scripting Games Results</title><description>Scripting Games Results&lt;br /&gt;
&lt;br /&gt;
Wow, what a couple of weeks.&amp;nbsp; Haven&#39;t posted much between the scripting games &amp;amp; Exchange 2010 training this week I&#39;ve been really busy.&amp;nbsp; Awaiting the official final results from the scripting games, but it looks like I&#39;ve managed to snag 3rd in the &#39;Advanced Division&#39;.&amp;nbsp; Well...at least according to &quot;Clint&#39;s Rules&quot; which are different from the official rules - you can download the spreadsheet I created &lt;a href=&quot;http://sites.google.com/site/outputredirectionfilehosting/2010ScriptingGames.xlsx?attredirects=0&amp;amp;d=1&quot;&gt;here&lt;/a&gt;.&amp;nbsp; What can I say...I&#39;m a little competitive by nature.&amp;nbsp; But &lt;b&gt;more importantly&lt;/b&gt;, man did I learn a lot from doing the exercises and from reading what other people submitted.&amp;nbsp; This week I&#39;ll try to post one thing I learned each day (maybe even starting today if I can resist the play SC2 beta urge) this week since class is over at 4 and I&#39;m all by myself.&amp;nbsp; In fact....here we go, the thing I remember first is:&lt;br /&gt;
&lt;br /&gt;
A way better method of looping/waiting for an event and then acting on it:&lt;br /&gt;
&lt;br /&gt;
Look at lines 34-44 in &lt;a href=&quot;http://scriptinggames.poshcode.org/code/768.xhtml&quot;&gt;Robert Robelo&#39;s Event 6 submission&lt;/a&gt;.&amp;nbsp; Compare that to all the nasty global variables and junk I made to work inside the event handler in &lt;a href=&quot;http://sites.google.com/site/outputredirectionfilehosting/Event6.ps1?attredirects=0&amp;amp;d=1&quot;&gt;my submission for Event 6&lt;/a&gt; (had to make a link to download, the link for my Event 6 submission blows up for some reason).&lt;br /&gt;
&lt;br /&gt;
Which kinda ties into thing #1.5 that I learned - the scriptblocks you supply to the -Action parameter in Register-*Event create a separate variable scope that does not inherit the variables from the script scope etc.&amp;nbsp; At least that&#39;s what it seems like....I could be wrong on that, I haven&#39;t looked for any documentation tbh.&lt;br /&gt;
&lt;br /&gt;
So, in my opinion, the way that Robert does it is WAY better than the way I did it, which basically boils down to:&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Create ONE global variable that will hold the event object when it is raised&lt;/li&gt;
&lt;li&gt;In the -action parameter of Register-*Event just assign the $Event automatic variable (or a property of it if that&#39;s all you&#39;re interested in) to the global variable that you created in your script&lt;/li&gt;
&lt;li&gt;Sleep loop until that global variable isn&#39;t $null anymore.&lt;/li&gt;
&lt;/ol&gt;In fact, I totally stole this method from him and used it in a later event that involved eventing.&amp;nbsp; So....thanks Robert :)&lt;br /&gt;
&lt;br /&gt;
Speaking of Robert, why aren&#39;t you reading&lt;a href=&quot;http://robertrobelo.spaces.live.com/blog/&quot;&gt; his blog &lt;/a&gt;instead of mine?&amp;nbsp; He rolled #1 in the Advanced division according to Clint&#39;s Rules....better&lt;a href=&quot;http://robertrobelo.spaces.live.com/blog/&quot;&gt; go check out what he has to say&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Until tomorrow,&amp;nbsp; bubye!!&amp;nbsp; v(^_^)v</description><link>http://outputredirection.blogspot.com/2010/06/scripting-games-results.html</link><author>noreply@blogger.com (v(^_^)v - Clint)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1555090447439276032.post-5975811576479609789</guid><pubDate>Sat, 17 Apr 2010 01:03:00 +0000</pubDate><atom:updated>2010-06-02T20:58:12.840-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Powershell</category><category domain="http://www.blogger.com/atom/ns#">Utility</category><title>Display a PowerShell session’s RAM and CPU utilization in the Title Bar</title><description>So, I had a few other things I’ve cooked up this week that I was thinking about posting, but this was too much fun this morning.&amp;nbsp; Here’s a little bit of code you can stick in your powershell profile that will update the title bar with the current PowerShell session’s memory usage (working set, technically) and CPU utilization.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;PowerShellColorizedScript&quot;&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;# Setup the objects for titlebar manipulation&lt;/span&gt;            
&lt;span style=&quot;color: darkgreen;&quot;&gt;# Append a #1,#2,#(n-1) to the process name if there are n pre-existing processes with the same&lt;/span&gt;            
&lt;span style=&quot;color: darkgreen;&quot;&gt;# name, as this is how the Performance Counter system references the instances.&lt;/span&gt;            
&lt;span style=&quot;color: orangered;&quot;&gt;$psProcess&lt;/span&gt; &lt;span style=&quot;color: darkgrey;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;gps&lt;/span&gt; &lt;span style=&quot;color: navy;&quot;&gt;-id&lt;/span&gt; &lt;span style=&quot;color: orangered;&quot;&gt;$PID&lt;/span&gt;            
&lt;span style=&quot;color: orangered;&quot;&gt;$psInstances&lt;/span&gt; &lt;span style=&quot;color: darkgrey;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;gps&lt;/span&gt; &lt;span style=&quot;color: navy;&quot;&gt;-Name&lt;/span&gt; &lt;span style=&quot;color: orangered;&quot;&gt;$psProcess&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;count&lt;/span&gt;            
&lt;span style=&quot;color: darkblue;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$psInstances&lt;/span&gt; &lt;span style=&quot;color: darkgrey;&quot;&gt;-gt&lt;/span&gt; &lt;span style=&quot;color: purple;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;            
&lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;            
&lt;span style=&quot;color: orangered;&quot;&gt;    $psName&lt;/span&gt; &lt;span style=&quot;color: darkgrey;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: darkred;&quot;&gt;&quot;{0}#{1}&quot;&lt;/span&gt; &lt;span style=&quot;color: darkgrey;&quot;&gt;-f&lt;/span&gt; &lt;span style=&quot;color: orangered;&quot;&gt;$psProcess&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;$(&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$psInstances&lt;/span&gt; &lt;span style=&quot;color: darkgrey;&quot;&gt;-&lt;/span&gt; &lt;span style=&quot;color: purple;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;            
&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;            
&lt;span style=&quot;color: darkblue;&quot;&gt;else&lt;/span&gt;            
&lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;            
&lt;span style=&quot;color: orangered;&quot;&gt;    $psName&lt;/span&gt; &lt;span style=&quot;color: darkgrey;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: orangered;&quot;&gt;$psProcess&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;name&lt;/span&gt;            
&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;            
&lt;span style=&quot;color: darkgreen;&quot;&gt;# Create the Performance Counter Object to track our sessions CPU usage&lt;/span&gt;            
&lt;span style=&quot;color: orangered;&quot;&gt;$Global:psPerfCPU&lt;/span&gt; &lt;span style=&quot;color: darkgrey;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;new-object&lt;/span&gt; &lt;span style=&quot;color: blueviolet;&quot;&gt;System.Diagnostics.PerformanceCounter&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt; &lt;span style=&quot;color: darkred;&quot;&gt;&quot;Process&quot;&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: darkred;&quot;&gt;&quot;% Processor Time&quot;&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: orangered;&quot;&gt;$psName&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;            
&lt;span style=&quot;color: darkgreen;&quot;&gt;# Get the first &#39;NextValue&#39;, which will be zero&lt;/span&gt;            
&lt;span style=&quot;color: orangered;&quot;&gt;$psPerfCPU&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;NextValue&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: darkgrey;&quot;&gt;|&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;Out-Null&lt;/span&gt;            
&lt;span style=&quot;color: darkgreen;&quot;&gt;# Create a timer object and set the interval to 1 second&lt;/span&gt;            
&lt;span style=&quot;color: orangered;&quot;&gt;$Global:psTimer&lt;/span&gt;   &lt;span style=&quot;color: darkgrey;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;New-Object&lt;/span&gt; &lt;span style=&quot;color: blueviolet;&quot;&gt;System.Timers.Timer&lt;/span&gt;            
&lt;span style=&quot;color: orangered;&quot;&gt;$psTimer&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;Interval&lt;/span&gt; &lt;span style=&quot;color: darkgrey;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: purple;&quot;&gt;1000&lt;/span&gt;            
&lt;span style=&quot;color: darkgreen;&quot;&gt;# Update the window&#39;s title bar every time the timer object raises the&lt;/span&gt;            
&lt;span style=&quot;color: darkgreen;&quot;&gt;# elapsed event&lt;/span&gt;            
&lt;span style=&quot;color: blue;&quot;&gt;Register-ObjectEvent&lt;/span&gt; &lt;span style=&quot;color: navy;&quot;&gt;-InputObject&lt;/span&gt; &lt;span style=&quot;color: orangered;&quot;&gt;$psTimer&lt;/span&gt; &lt;span style=&quot;color: navy;&quot;&gt;-EventName&lt;/span&gt; &lt;span style=&quot;color: blueviolet;&quot;&gt;Elapsed&lt;/span&gt; &lt;span style=&quot;color: navy;&quot;&gt;-Action&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;            
&lt;span style=&quot;color: orangered;&quot;&gt;    $psInfo&lt;/span&gt; &lt;span style=&quot;color: darkgrey;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;Get-Process&lt;/span&gt; &lt;span style=&quot;color: navy;&quot;&gt;-id&lt;/span&gt; &lt;span style=&quot;color: orangered;&quot;&gt;$pid&lt;/span&gt;            
&lt;span style=&quot;color: teal;&quot;&gt;    [int]&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$ws&lt;/span&gt; &lt;span style=&quot;color: darkgrey;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: orangered;&quot;&gt;$psInfo&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;workingset&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: purple;&quot;&gt;1MB&lt;/span&gt;            
&lt;span style=&quot;color: teal;&quot;&gt;    [int]&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$cpu&lt;/span&gt; &lt;span style=&quot;color: darkgrey;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: orangered;&quot;&gt;$psPerfCPU&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;NextValue&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: darkgrey;&quot;&gt;/&lt;/span&gt; &lt;span style=&quot;color: orangered;&quot;&gt;$env:NUMBER_OF_PROCESSORS&lt;/span&gt;            
&lt;span style=&quot;color: orangered;&quot;&gt;    $Host&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;ui&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;rawui&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;WindowTitle&lt;/span&gt; &lt;span style=&quot;color: darkgrey;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: darkred;&quot;&gt;&quot;$($CurrentUser.Name) $($Host.Name) $($Host.Version) | $((get-location).ProviderPath) | RAM: $ws MB CPU: $cpu%&quot;&lt;/span&gt;            
&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt; &lt;span style=&quot;color: darkgrey;&quot;&gt;|&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;Out-Null&lt;/span&gt;            
&lt;span style=&quot;color: orangered;&quot;&gt;$psTimer&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;start&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;
The hardest part was getting the CPU utilization right, but these two posts spell out the details pretty well:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;http://blogs.msdn.com/dotnetinterop/archive/2007/02/02/system-diagnostics-performancecounter-and-processor-time-on-multi-core-or-multi-cpu.aspx&quot; title=&quot;http://blogs.msdn.com/dotnetinterop/archive/2007/02/02/system-diagnostics-performancecounter-and-processor-time-on-multi-core-or-multi-cpu.aspx&quot;&gt;http://blogs.msdn.com/dotnetinterop/archive/2007/02/02/system-diagnostics-performancecounter-and-processor-time-on-multi-core-or-multi-cpu.aspx&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://blogs.msdn.com/bclteam/archive/2006/06/02/618156.aspx&quot; title=&quot;http://blogs.msdn.com/bclteam/archive/2006/06/02/618156.aspx&quot;&gt;http://blogs.msdn.com/bclteam/archive/2006/06/02/618156.aspx&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;Happy Friday!</description><link>http://outputredirection.blogspot.com/2010/04/display-powershell-sessions-ram-and-cpu.html</link><author>noreply@blogger.com (v(^_^)v - Clint)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1555090447439276032.post-2622202170317781735</guid><pubDate>Fri, 09 Apr 2010 21:11:00 +0000</pubDate><atom:updated>2012-01-07T20:30:45.508-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Error Handling</category><category domain="http://www.blogger.com/atom/ns#">Powershell</category><title>PowerShell’s Try/Catch/Finally and –erroraction Stop</title><description>Update: From an anonymous commenter, evidently error handing when using &quot;-erroraction Stop&quot; now works as one would expect in PowerShell version 3!&amp;nbsp; However, if you&#39;re still using version 2 the information below should help you out. &lt;br /&gt;
&lt;br /&gt;
When planning for exception handling, I’ve recently learned that forcing execution to stop by setting $erroractionpreference to ‘Stop’ or by using the –erroraction common parameter requires some special handling.&lt;br /&gt;
&lt;br /&gt;
First let’s see what doesn’t work even though it seems like it should.&amp;nbsp; Handling a normal terminating error is fairly straightforward:&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHEz7RxWwNbvUeRZFz1W30yFur7u6VpwkFS9Hco8nrpHBx9zprLUTXz-LcyBLP1yD_GGAauh8eAFJdEf__3gqPOecWJiIvk86adVUTpMiQy7gHEhy0X4hTFt5B5JPH9KNOcr2AUChniz3J/s1600-h/image%5B8%5D.png&quot;&gt;&lt;img alt=&quot;image&quot; border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfSIco_zTq-mzTYrcJpAlh6TEK5W2hyphenhyphenU9iMj81YcxMj2GfIMuhQqNL0L2eQGoqVxQqQG1Bcpqwi4g-OyD5gbEJy62DzNb5yO_m6qyAyUYG1uvlkNr7NBsQXJEGJeMR1NWkBUy8u-9SO_X8/?imgmax=800&quot; style=&quot;border: 0px none; display: inline;&quot; title=&quot;image&quot; width=&quot;716&quot; /&gt;&lt;/a&gt; &lt;br /&gt;
&lt;br /&gt;
Here we encountered an exception, got the exception’s type by inspecting the first element in the typenames member of the first error record’s exception’s base object, and then used that type name to catch the exception.&amp;nbsp; This worked whether or not we specified the –ea or –erroraction parameter.&amp;nbsp; This works because a ParameterBindingException is a terminating error.&amp;nbsp; However, let’s see what happens when we try the same thing with an error that &lt;i&gt;isn’t&lt;/i&gt; of terminating error family:&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOF1RtvKk2b_h3bjBapVRuU-TV6eDFvNIP-PHiOb7D2j5PLvJ0F-JfjnRMnAQ5pVy4Dv-q7YRLj82lbsK2nbulLoaTVH3vU4eBCWaPl6XyuduJpsAMSGcUykLKhypgqFkOxgcIlFjBm1Wf/s1600-h/image%5B3%5D.png&quot;&gt;&lt;img alt=&quot;image&quot; border=&quot;0&quot; height=&quot;340&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjiy_8eW7-5urhRFCsEPUg9chVtNKuSEdSsxNhu2Anvay1iTNAx5Z2jw-QifOvE638WFUWklFYdJZXbUQJmSCvX30O4HSt_zIDR7cjK0GTELFE_2V5OWnf5q5omFp3SGMs6Ce2d3Ybcaqg/?imgmax=800&quot; style=&quot;border: 0px none; display: inline;&quot; title=&quot;image&quot; width=&quot;718&quot; /&gt;&lt;/a&gt; &lt;br /&gt;
&lt;br /&gt;
Hmm, bugger.&amp;nbsp; We tried the same pattern, but this time it just doesn’t work.&amp;nbsp; But…why?&amp;nbsp; Without getting too long winded about it, I tried looking back through the automatic $error variable but couldn’t find an answer.&amp;nbsp; So I tried a different tactic:&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikHDsa7T6Juo7KDRERwbPj8OQ9w4nFQ63DMF1exZvg00EROX6Z51GT7rSkV20NaVM4waA4HqHVomKmSmBvo1ALNYQynb_kX9Jg5A3QtKD-IjBomNLSLx05Nmkg_Dr0wNv9AUxdaMMpx6aF/s1600-h/image%5B13%5D.png&quot;&gt;&lt;img alt=&quot;image&quot; border=&quot;0&quot; height=&quot;178&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgY1IU5MBtkK3Y62r1qsdLP55De57A7Yqdy4sKM0sN2gPTz5Drg_PFfNLGaDqqBVZ-TxYnVhIyqePaNYhEtjTfPOmRpj_IYmHncRM37Giz4yS9dd0i-4pwtqsNF-KT7vp6sFcfbMMlUfvP/?imgmax=800&quot; style=&quot;border: 0px none; display: inline;&quot; title=&quot;image&quot; width=&quot;954&quot; /&gt;&lt;/a&gt; &lt;br /&gt;
&lt;br /&gt;
Aha!&amp;nbsp; When we use –erroraction stop, the terminating exception &lt;i&gt;isn’t&lt;/i&gt; the error that was encountered but an exception of type System.Management.Automation.ActionPreferencesStopException!&amp;nbsp; But…wait, if that’s true, how do we know what type of error was encountered?&amp;nbsp; Almost inexplicably the automatic variable $_ is set to the error record of the error that was encountered.&amp;nbsp; If you know why, please share in the comments or send me an e-mail.&amp;nbsp; Anyway, we can use that to &lt;i&gt;re-throw&lt;/i&gt; the error as a terminating exception that can be caught and handled:&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjZ0m2Nd9Zj_3BVYqjlySPu2h55aBdYWgAbTrW7t9O1BCQqAxjIGznPwrdZJjjSHg4YUxggzY53yQYuW9rWc7osRoLswz7qWaOMBqg_5kQ93yb52fumSlr5wwQI3Ka9sIxfP_NauyESi29/s1600-h/image%5B17%5D.png&quot;&gt;&lt;img alt=&quot;image&quot; border=&quot;0&quot; height=&quot;268&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwTpE_4iKR8-pfpi0q8xrqRXIIWphDjLCcebd_BGjQey7klxmncryLybhcm6TXLt2aVnR_RH-FmIsx3nwbmZDwVLlwqTB-Aea98IAhT8n4WlI1qFBqCvNlWyV6N2sXuu6MfCCX-shHbNDJ/?imgmax=800&quot; style=&quot;border: 0px none; display: inline;&quot; title=&quot;image&quot; width=&quot;492&quot; /&gt;&lt;/a&gt; &lt;br /&gt;
&lt;br /&gt;
Basically we just wrap our command that makes use of the –erroraction stop inside two try/catch blocks.&amp;nbsp; The inner block is used to trap the ActionPreferenceStopException generated by the erroraction parameter.&amp;nbsp; In the inner catch block we throw the exception for the error that was caught which is then caught by the outer catch block statements and can the be handled.&amp;nbsp; So, let’s finish with a generic pattern that one could turn into a code snippet or something:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 625px;&quot;&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;5&quot; cellspacing=&quot;0&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;     &lt;td valign=&quot;top&quot;&gt;&lt;div style=&quot;background: none repeat scroll 0% 0% rgb(206, 206, 206); font-family: Consolas,Lucida Console; font-size: 10pt; padding: 5px;&quot;&gt;
001&lt;br /&gt;
002&lt;br /&gt;
003&lt;br /&gt;
004&lt;br /&gt;
005&lt;br /&gt;
006&lt;br /&gt;
007&lt;br /&gt;
008&lt;br /&gt;
009&lt;br /&gt;
010&lt;br /&gt;
011&lt;br /&gt;
012&lt;br /&gt;
013&lt;br /&gt;
014&lt;br /&gt;
015&lt;br /&gt;
016&lt;br /&gt;
017&lt;br /&gt;
018&lt;br /&gt;
019&lt;br /&gt;
020&lt;br /&gt;
021&lt;br /&gt;
022&lt;br /&gt;
023&lt;br /&gt;
024&lt;br /&gt;
025&lt;br /&gt;
026&lt;br /&gt;
027&lt;br /&gt;
028&lt;/div&gt;
&lt;/td&gt;     &lt;td nowrap=&quot;nowrap&quot; valign=&quot;top&quot;&gt;&lt;div style=&quot;background: none repeat scroll 0% 0% rgb(252, 252, 252); font-family: Consolas,Lucida Console; font-size: 10pt; padding: 5px;&quot;&gt;
&lt;span style=&quot;color: darkblue;&quot;&gt;try&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkblue;&quot;&gt;&amp;nbsp; try&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;# Command that uses -erroraction stop or $erroractionpreference = &#39;Stop&#39;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;# Here we catch the Exception generated by the ErrorAction &quot;Stop&quot;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;# Only necessary if there is any processing we want to do if the&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;# exception is of type ActionPreferenceStopExecution,&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;#  otherwise this block can be deleted &lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: darkblue;&quot;&gt;catch&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;[System.Management.Automation.ActionPreferenceStopException]&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;# Error Handling specific to ActionPreferenceStopException goes here&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;# Rethrow the &quot;real&quot; exception as a terminating error&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: darkblue;&quot;&gt;Throw&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$_&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;exception&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;# All errors are caught and rethrown to the outer try/catch block&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;# as terminating errors to be handled.&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: darkblue;&quot;&gt;catch&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: darkblue;&quot;&gt;Throw&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$_&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;exception&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;# Here we can resume exception type handling as usual&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkblue;&quot;&gt;catch&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;#[System.Management.Automation.ItemNotFoundException]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: darkred;&quot;&gt;&quot;Got it!&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt; &lt;/div&gt;
&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt; &lt;/table&gt;
&lt;/div&gt;
&lt;br /&gt;
And with that, Happy Friday!</description><link>http://outputredirection.blogspot.com/2010/04/powershells-trycatchfinally-and.html</link><author>noreply@blogger.com (v(^_^)v - Clint)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfSIco_zTq-mzTYrcJpAlh6TEK5W2hyphenhyphenU9iMj81YcxMj2GfIMuhQqNL0L2eQGoqVxQqQG1Bcpqwi4g-OyD5gbEJy62DzNb5yO_m6qyAyUYG1uvlkNr7NBsQXJEGJeMR1NWkBUy8u-9SO_X8/s72-c?imgmax=800" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1555090447439276032.post-8589733142445202022</guid><pubDate>Fri, 02 Apr 2010 17:12:00 +0000</pubDate><atom:updated>2010-04-18T07:28:14.020-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">group policy</category><category domain="http://www.blogger.com/atom/ns#">Powershell</category><category domain="http://www.blogger.com/atom/ns#">Utility</category><title>Early preview of Group Policy Backup &amp;amp; Search Module</title><description>Alright, it’s taken WAY longer than I thought it would, but I finally have something I think is worth sharing in its &lt;i&gt;very&lt;/i&gt; unfinished state.&amp;nbsp; First, what still sucks: the help is only slightly better than useless, the code itself is a bit jumbled and not well commented, not everything is formatted nicely when written to output, only 3 extensions (Software Installation, Scripts, and Policy/Registry – the big 3 for me) are implemented, and while the backup function works, you’re pretty much on your own for configuration at the moment.&amp;nbsp; That said, what does work is pretty cool (in my opinion):&amp;nbsp; You can search inside of your live group policy objects, as well as any archived XML Reports from Get-GPOReport, and get meaningful output!&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
Let’s go through an example.&amp;nbsp; First we need to get our new module up and running.&amp;nbsp; You can download the code for this post &lt;a href=&quot;http://clintgputilities.googlecode.com/files/cgpo.7z&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&amp;nbsp; (Don’t have 7-zip?&amp;nbsp; &lt;a href=&quot;http://www.7-zip.org/&quot; target=&quot;_blank&quot;&gt;Get it&lt;/a&gt;.)&amp;nbsp; Once you have the code downloaded extract the contents to one of your module directories:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;%Windir%\System32\WindowsPowershell\v1.0\Modules&lt;/li&gt;
&lt;li&gt;&amp;lt;My Documents&amp;gt;\WindowsPowerShell\Modules&lt;/li&gt;
&lt;/ul&gt;A little up front configuration is needed.&amp;nbsp; Inside our module’s folder is a file named cgpo.config.xml.dist.&amp;nbsp; Create a copy of the file, rename it to cgpo.config.xml, and open it up in your editor of choice.&amp;nbsp; Find the following lines:&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;&amp;lt;CGPOXmlCachePath&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!-- If this Element is left blank the module will default to a subdirectory of the user&#39;s temp directory. --&amp;gt;      &lt;br /&gt;
&amp;lt;/CGPOXmlCachePath&amp;gt;      &lt;br /&gt;
&amp;lt;Domain&amp;gt;      &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!-- Help Goes Here --&amp;gt;      &lt;br /&gt;
&amp;lt;/Domain&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The only required information is your domain, entered in the ‘contoso.com’ format.&amp;nbsp; Type that in after the (admittedly unhelpful) comment.&amp;nbsp; If you would like to specify a directory to use to cache XML reports, enter that following the comment in the CGPOXmlCachePath element.&amp;nbsp; Our config file should look something like:&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;&amp;lt;CGPOXmlCachePath&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!-- If this Element is left blank the module will default to a subdirectory of the user&#39;s temp directory. –&amp;gt;      &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; C:\Temp\GPOXmlCache      &lt;br /&gt;
&amp;lt;/CGPOXmlCachePath&amp;gt;      &lt;br /&gt;
&amp;lt;Domain&amp;gt;      &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!-- Help Goes Here –&amp;gt;      &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; sub.domain.com      &lt;br /&gt;
&amp;lt;/Domain&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Save the config file and open up ye’ PowerShell.&amp;nbsp; First load up the grouppolicy module from Win 7’s RSAT, then our new module.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;PS&amp;gt; ipmo grouppolicy     &lt;br /&gt;
PS&amp;gt; ipmo cgpo&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
If all is well, you should just get your prompt back.&amp;nbsp; Next, let’s check two variables to make sure our config file was read properly.&amp;nbsp; Your output should look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;PS&amp;gt; $CGPO_Domain&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt; my.domain.com      &lt;br /&gt;
PS&amp;gt; $CGPO_ReportXmlCachePath      &lt;br /&gt;
C:\Users\CLINT-~1\AppData\Local\Temp\CGPOReportXmlCache&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Okay, all looks well.&amp;nbsp; Let’s jump in!&amp;nbsp; For kicks we’ll just do a “simple” search of our live GPOs.&amp;nbsp; Your results will, obviously, vary.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;PS&amp;gt; Search-CGPOReports “printer”&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;ScriptType Command&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; Parameters&lt;br /&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;&amp;nbsp;&amp;nbsp; ----------&lt;br /&gt;
Logon&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fix-printers-Shortcut.cmd&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; phs&lt;br /&gt;
Logon&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fix-printers-Shortcut.cmd&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; adm&lt;br /&gt;
Logon&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fix-printers-Shortcut.cmd&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; fes&lt;br /&gt;
Logon&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fix-printers-Shortcut.cmd&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; lms&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Check published state     &lt;br /&gt;
Category&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Printers      &lt;br /&gt;
GPOName&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Default Domain Controller Policy      &lt;br /&gt;
GPOReportPath : C:\Users\clint-admin\AppData\Local\Temp\CGPOReportXmlCache\1.xml &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Show only specified Control Panel items     &lt;br /&gt;
Category&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Control Panel      &lt;br /&gt;
GPOName&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : logon-RESTRICTED-autoLogon-phs-libusers      &lt;br /&gt;
GPOReportPath : C:\Users\clint-admin\AppData\Local\Temp\CGPOReportXmlCache\105.xml&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The formatting is ugly due to the default formatters in PowerShell.&amp;nbsp; If all we want is a textual display of the results we can use the –summarize switch&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;PS&amp;gt; Search-CGPOReports “printer” –summarize&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;ScriptType Command&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; Parameters&lt;br /&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;&amp;nbsp;&amp;nbsp; ----------&lt;br /&gt;
Logon&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fix-printers-Shortcut.cmd&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; phs&lt;br /&gt;
Logon&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fix-printers-Shortcut.cmd&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; adm&lt;br /&gt;
Logon&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fix-printers-Shortcut.cmd&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; fes&lt;br /&gt;
Logon&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fix-printers-Shortcut.cmd&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; lms&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&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;&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; Category&lt;br /&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; --------&lt;br /&gt;
Check published state&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; Printers&lt;br /&gt;
Show only specified Control Panel items&amp;nbsp; Control Panel&lt;br /&gt;
Browse the network to find printers&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Control Panel/Pri...&lt;br /&gt;
Show only specified Control Panel items&amp;nbsp; Control Panel&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
OK, nifty, but what is we want to dig around inside a specific GPO?&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;PS&amp;gt; $x = Get-GPOReport –Name &amp;lt;GPONAME&amp;gt; –ReportType XML | Get-CGPOReport&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt; PS&amp;gt; $x | Get-Member&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Or look at/search historical (backup) information?&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;PS&amp;gt; $y = Get-CGPOReport –ReportPath “C:\GPOBackupLocation”&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt; PS&amp;gt; Search-CGPOReports –gpoReportPath “C:\CGPOBackupLocation” –pattern “Microsoft Office”&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Or find all the current group policy objects that contain logon/logoff/startup/shutdown scripts?&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;PS&amp;gt; Update-GPOReportCache&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt; PS&amp;gt; $z = Get-CGPOReport –reportPath $CGPO_ReportXmlCachePath –IncludedExtensionDetails “Scripts”&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Explore it, have fun, PLEASE PLEASE give me your feedback if you have any.&amp;nbsp; You can leave it in the comments here, or feel free to send me an email directly.&amp;nbsp; You can get the latest build via svn:&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;svn checkout &lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;&lt;b&gt;&lt;i&gt;http&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;://clintgputilities.googlecode.com/svn/trunk/ clintgputilities-read-only&lt;/span&gt;</description><link>http://outputredirection.blogspot.com/2010/04/early-preview-of-group-policy-backup.html</link><author>noreply@blogger.com (v(^_^)v - Clint)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1555090447439276032.post-6956057310020085663</guid><pubDate>Fri, 12 Mar 2010 19:34:00 +0000</pubDate><atom:updated>2010-11-01T11:07:34.523-07:00</atom:updated><title>PowerShell Resources – Free and Otherwise</title><description>Haven’t had much time to work on our group policy module lately, I’ve been pretty busy getting my co-worker’s collective feet wet in PowerShell.&amp;nbsp; In the process I’ve been trying to find as many quality resources as I can for them to help them help themselves.&amp;nbsp; Since I don’t have much to share on the csb.grouppolicy module front, here are the resources that I can remember (haha) and use all the time:&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h3&gt;Free&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;http://powershell.com/cs/blogs/ebook/default.aspx&quot; title=&quot;http://powershell.com/cs/blogs/ebook/default.aspx&quot;&gt;http://powershell.com/cs/blogs/ebook/default.aspx&lt;/a&gt;      &lt;br /&gt;
Free eBook by Dr. Tobias Weltner, who you may recognize as the creator of PowerShell Plus.&amp;nbsp; 500+ pages of PowerShell goodness.&amp;nbsp; My guys love it.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.powershellcommunity.org/Default.aspx?base&quot; title=&quot;http://www.powershellcommunity.org/Default.aspx?base&quot;&gt;http://www.powershellcommunity.org/Default.aspx?base&lt;/a&gt;      &lt;br /&gt;
Good launching point for learning PowerShell and exploring the PowerShell community.&amp;nbsp; The community Blogs page in particular is a favorite of mine.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://powershell.com/cs/&quot; title=&quot;http://powershell.com/cs/&quot;&gt;http://powershell.com/cs/&lt;/a&gt;      &lt;br /&gt;
Another good launch point for learning and exploring.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://poshcode.org/&quot; title=&quot;http://poshcode.org/&quot;&gt;http://poshcode.org/&lt;/a&gt;      &lt;br /&gt;
Looking for a function or script?&amp;nbsp; Look here, it may exist already.&amp;nbsp; Have a script or function to share, post away.&amp;nbsp; Love it.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.powershellanalyzer.com/&quot; title=&quot;http://www.powershellanalyzer.com/&quot;&gt;http://www.powershellanalyzer.com/&lt;/a&gt;      &lt;br /&gt;
A great PowerShell host.&amp;nbsp; We’ve found that it really helps when inspecting all the different objects that you end up working with in PowerShell.&amp;nbsp; And the chart output options are just plain cool.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.powergui.org/&quot;&gt;http://www.powergui.org/&lt;/a&gt;, &lt;a href=&quot;http://www.powergui.org/kbcategory.jspa?categoryID=21&quot; title=&quot;http://www.powergui.org/kbcategory.jspa?categoryID=21&quot;&gt;http://www.powergui.org/kbcategory.jspa?categoryID=21&lt;/a&gt;      &lt;br /&gt;
Another great PowerShell host that extends the functionality of PowerShell above and beyond.&amp;nbsp; Makes PowerShell a pointy-clicky affair that’s so easy, even your boss can use it! Also comes with a very competent script editor.&amp;nbsp; The second link is to all the ‘PowerPacks’ that have been created.&amp;nbsp; I love the Exchange 2003 one.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.codeplex.com/Pscx&quot; title=&quot;http://www.codeplex.com/Pscx&quot;&gt;http://www.codeplex.com/Pscx&lt;/a&gt;      &lt;br /&gt;
Essential PowerShell snapin/module.&amp;nbsp; I don’t think I could function without the ping-host and resolve-host functions.&amp;nbsp; Don’t think about it, just download it and set it up in your profile.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://code.msdn.microsoft.com/PowerShellPack&quot; title=&quot;http://code.msdn.microsoft.com/PowerShellPack&quot;&gt;http://code.msdn.microsoft.com/PowerShellPack&lt;/a&gt;      &lt;br /&gt;
A good module for PowerShell (v2 only I believe).&amp;nbsp; I found the WPK module (WPF functions/scripts) is a bit difficult to wrap my brain around without a form designer for layout, but the TaskScheduler module is great, as is the IsePack.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.primaltools.com/downloads/communitytools/signup.asp?tool=pforms&quot; title=&quot;http://www.primaltools.com/downloads/communitytools/signup.asp?tool=pforms&quot;&gt;http://www.primaltools.com/downloads/communitytools/signup.asp?tool=pforms&lt;/a&gt;      &lt;br /&gt;
The free community edition of Sapien’s PrimalForms product.&amp;nbsp; Makes writing admin GUIs much easier.&amp;nbsp; Requires Name/e-mail submission, but is well worth the few seconds.&amp;nbsp; Unfortunately it doesn’t save the script logic you put into the form, so if you start to get ambitious you’ll probably want to upgrade to the paid version.&amp;nbsp; I sure did, $150 well spent imho.&lt;/li&gt;
&lt;/ul&gt;&lt;h3&gt;Not Quite As Free&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;http://www.idera.com/Products/PowerShell/PowerShell-Plus/&quot; title=&quot;http://www.idera.com/Products/PowerShell/PowerShell-Plus/&quot;&gt;http://www.idera.com/Products/PowerShell/PowerShell-Plus/&lt;/a&gt;      &lt;br /&gt;
Undeniably my #1 PowerShell tool.&amp;nbsp; With the new community script searching functions in 3.1, competent code editor, debugger, variable inspector, and learning center, I can unreservedly recommend this to anyone with $145 to spend.&amp;nbsp; If you can only buy one PowerShell utility, buy this one.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.softwarefx.com/sfxSqlProducts/powergadgets/&quot; title=&quot;http://www.softwarefx.com/sfxSqlProducts/powergadgets/&quot;&gt;http://www.softwarefx.com/sfxSqlProducts/powergadgets/&lt;/a&gt;      &lt;br /&gt;
Way too cool.&amp;nbsp; Used it to build a ‘live’ help-desk statistics gadget for our department.&amp;nbsp; Impressed the boss so much he licensed it for everyone in a heartbeat.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.manning.com/payette2/&quot; title=&quot;http://www.manning.com/payette2/&quot;&gt;http://www.manning.com/payette2/&lt;/a&gt;      &lt;br /&gt;
As far as I’m concerned, &lt;i&gt;the&lt;/i&gt; book to buy.&amp;nbsp; I read once “If you want to learn Debian, install Debian. If you want to learn Fedora, install Fedora. If you want to learn &lt;i&gt;Linux&lt;/i&gt;, install Slackware.”.&amp;nbsp; This book is kinda like that.&amp;nbsp; There’s a lot of books on how to use PowerShell in a particular scenario, and they’re great books, but they don’t necessarily teach you &lt;i&gt;PowerShell&lt;/i&gt;.&amp;nbsp; My copy of this for v1 is tattered, dog-eared and well worn for good reason. If you want to learn PowerShell, pre-order this book and start reading.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.primaltools.com/products/info.asp?p=PrimalForms&quot; title=&quot;http://www.primaltools.com/products/info.asp?p=PrimalForms&quot;&gt;http://www.primaltools.com/products/info.asp?p=PrimalForms&lt;/a&gt;      &lt;br /&gt;
The pay for version of the PrimalForms product from Sapien.&amp;nbsp; The form designer portion is great.&amp;nbsp; My only real gripe with the program is that it seems like the script editing &amp;amp; execution portion should be tied into PrimalScript (assuming you have it installed) much tighter than ‘export and open’.&amp;nbsp; Without the debugger, bookmarking, etc. functions that I’m used to using in PrimalScript…it’s a little painful to use to do much code logic in.&amp;nbsp; But, like I said above, everything considered it’s $150 well spent.&lt;/li&gt;
&lt;/ul&gt;Hope you can find something new and useful in that list!&amp;nbsp; If we end up doing some in-house training on how to use some of these tools, perhaps I can post tutorials or something as a result….hmmm.&amp;nbsp; If you have any favorite tools that I don’t have listed, please post them in the comments section; I love new toys!</description><link>http://outputredirection.blogspot.com/2010/03/powershell-resources-free-and-otherwise.html</link><author>noreply@blogger.com (v(^_^)v - Clint)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1555090447439276032.post-5320684815068433550</guid><pubDate>Wed, 24 Feb 2010 16:54:00 +0000</pubDate><atom:updated>2010-02-24T08:54:22.121-08:00</atom:updated><title>Snippets for Comment Based Help and Advanced Function Parameters in Powershell v2</title><description>Been working quite a bit on the module for group policy, and almost have something I feel is worth sharing.&amp;nbsp; In the meantime, if you have a script editor that supports the concept of “snippets”, or saved re-usable bits of script code, you might find this little bit useful.&amp;nbsp; I’ve had a hard time remembering the syntax and all the options for some of the new cool stuff we can use in scripts and functions in Powershell v2, so I saved these little bits after scouring the output of Get-Help for comment based help and advanced functions for (hopefully) the last time, haha.&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
Comment Based Help:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 600px;&quot;&gt;&lt;table border=&quot;0&quot; cellpadding=&quot;5&quot; cellspacing=&quot;0&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;     &lt;td valign=&quot;Top&quot;&gt;&lt;div style=&quot;background: none repeat scroll 0% 0% rgb(206, 206, 206); font-family: Consolas,Lucida Console; font-size: 10pt; padding: 5px;&quot;&gt;001&lt;br /&gt;
002&lt;br /&gt;
003&lt;br /&gt;
004&lt;br /&gt;
005&lt;br /&gt;
006&lt;br /&gt;
007&lt;br /&gt;
008&lt;br /&gt;
009&lt;br /&gt;
010&lt;br /&gt;
011&lt;br /&gt;
012&lt;br /&gt;
013&lt;br /&gt;
014&lt;br /&gt;
015&lt;br /&gt;
016&lt;br /&gt;
017&lt;br /&gt;
018&lt;br /&gt;
019&lt;br /&gt;
020&lt;br /&gt;
021&lt;br /&gt;
022&lt;br /&gt;
023&lt;br /&gt;
024&lt;br /&gt;
025&lt;br /&gt;
026&lt;br /&gt;
027&lt;br /&gt;
028&lt;br /&gt;
029&lt;br /&gt;
030&lt;br /&gt;
031&lt;br /&gt;
032&lt;br /&gt;
033&lt;br /&gt;
034&lt;br /&gt;
035&lt;br /&gt;
036&lt;br /&gt;
037&lt;br /&gt;
038&lt;br /&gt;
039&lt;br /&gt;
040&lt;br /&gt;
041&lt;br /&gt;
042&lt;br /&gt;
043&lt;br /&gt;
044&lt;br /&gt;
045&lt;br /&gt;
046&lt;br /&gt;
047&lt;br /&gt;
048&lt;br /&gt;
049&lt;br /&gt;
050&lt;br /&gt;
051&lt;br /&gt;
052&lt;br /&gt;
053&lt;br /&gt;
054&lt;br /&gt;
055&lt;br /&gt;
056&lt;br /&gt;
057&lt;br /&gt;
058&lt;br /&gt;
059&lt;br /&gt;
060&lt;br /&gt;
061&lt;br /&gt;
062&lt;br /&gt;
063&lt;br /&gt;
064&lt;br /&gt;
065&lt;br /&gt;
066&lt;br /&gt;
067&lt;br /&gt;
068&lt;/div&gt;&lt;/td&gt;     &lt;td nowrap=&quot;NOWRAP&quot; valign=&quot;Top&quot;&gt;&lt;div style=&quot;background: none repeat scroll 0% 0% rgb(252, 252, 252); font-family: Consolas,Lucida Console; font-size: 10pt; padding: 5px;&quot;&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;&amp;lt;#  &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;.SYNOPSIS&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;A brief description of the function or script. This keyword can be used&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;only once in each topic.&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;.DESCRIPTION&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;A detailed description of the function or script. This keyword can be&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;used only once in each topic.&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;.PARAMETER  &lt;parameter-name&gt;&lt;/parameter-name&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;The description of a parameter. You can include a Parameter keyword for&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;each parameter in the function or script syntax.&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;.EXAMPLE&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;A sample command that uses the function or script, optionally followed&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;by sample output and a description. Repeat this keyword for each example.&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;.INPUTS&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;The Microsoft .NET Framework types of objects that can be piped to the&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;function or script. You can also include a description of the input &lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;objects.&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;.OUTPUTS&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;The .NET Framework type of the objects that the cmdlet returns. You can&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;also include a description of the returned objects.&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;.NOTES&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;Additional information about the function or script.&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;.LINK&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;The name of a related topic. Repeat this keyword for each related topic.&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;.COMPONENT&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;The technology or feature that the function or script uses, or to which&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;it is related. This content appears when the Get-Help command includes&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;the Component parameter of Get-Help.&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;.ROLE&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;The user role for the Help topic. This content appears when the Get-Help&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;command includes the Role parameter of Get-Help.&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;.FUNCTIONALITY&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;The intended use of the function. This content appears when the Get-Help&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;command includes the Functionality parameter of Get-Help.&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;.FORWARDHELPTARGETNAME &lt;command-name&gt;&lt;/command-name&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;Redirects to the Help topic for the specified command. You can redirect&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;users to any Help topic, including Help topics for a function, script,&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;cmdlet, or provider. &lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;.FORWARDHELPCATEGORY  &lt;category&gt;&lt;/category&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;Specifies the Help category of the item in ForwardHelpTargetName.&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;Valid values are Alias, Cmdlet, HelpFile, Function, Provider, General,&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;FAQ, Glossary, ScriptCommand, ExternalScript, Filter, or All. Use this&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;keyword to avoid conflicts when there are commands with the same name.&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;.REMOTEHELPRUNSPACE &lt;pssession-variable&gt;&lt;/pssession-variable&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;Specifies a session that contains the Help topic. Enter a variable that&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;contains a PSSession. This keyword is used by the Export-PSSession&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;cmdlet to find the Help topics for the exported commands.&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;.EXTERNALHELP  &lt;xml file=&quot;&quot; help=&quot;&quot; path=&quot;&quot;&gt;&lt;/xml&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;Specifies the path to an XML-based Help file for the script or function.  &lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;For more information about the cmdlet Help XML-based Help file format,&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;see &quot;How to Create Cmdlet Help&quot; in the MSDN (Microsoft Developer Network) &lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color: darkgreen;&quot;&gt;library at http://go.microsoft.com/fwlink/?LinkID=123415.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;#&amp;gt;&lt;/span&gt; &lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt; &lt;/table&gt;&lt;/div&gt;&lt;br /&gt;
Advanced Function Parameters:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 600px;&quot;&gt;&lt;table border=&quot;0&quot; cellpadding=&quot;5&quot; cellspacing=&quot;0&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;     &lt;td valign=&quot;Top&quot;&gt;&lt;div style=&quot;background: none repeat scroll 0% 0% rgb(206, 206, 206); font-family: Consolas,Lucida Console; font-size: 10pt; padding: 5px;&quot;&gt;001&lt;br /&gt;
002&lt;br /&gt;
003&lt;br /&gt;
004&lt;br /&gt;
005&lt;br /&gt;
006&lt;br /&gt;
007&lt;br /&gt;
008&lt;br /&gt;
009&lt;br /&gt;
010&lt;br /&gt;
011&lt;br /&gt;
012&lt;br /&gt;
013&lt;br /&gt;
014&lt;br /&gt;
015&lt;br /&gt;
016&lt;br /&gt;
017&lt;br /&gt;
018&lt;br /&gt;
019&lt;br /&gt;
020&lt;br /&gt;
021&lt;br /&gt;
022&lt;br /&gt;
023&lt;/div&gt;&lt;/td&gt;     &lt;td nowrap=&quot;NOWRAP&quot; valign=&quot;Top&quot;&gt;&lt;div style=&quot;background: none repeat scroll 0% 0% rgb(252, 252, 252); font-family: Consolas,Lucida Console; font-size: 10pt; padding: 5px;&quot;&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: lightblue;&quot;&gt;parameter&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;#Mandatory=$false,&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;#Position=0,&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;#ParameterSetName=&quot;SetName&quot;,&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;#ValueFromPipeline=$false,&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;#ValueFromPipelineByPropertyName=$false,&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;#ValueFromRemainingArguments=$false,&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: black;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;#HelpMessage=&quot;Help goes here&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;#[Alias(&quot;Alias&quot;]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;#[AllowNull()]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;#[AllowEmptyString()]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;#[AllowEmptyCollection()]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;#[ValidateCount(min,max)]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;#[ValidateLength(min,max)]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;#[ValidatePattern(&quot;RegEx Goes Here&quot;)]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;#[ValidateRange(min,max)]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;#[ValidateScript({ $_ -eq &quot;something&quot; })]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;#[ValidateSet(&quot;One&quot;,&quot;Two&quot;,&quot;Three&quot;)]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;#[ValidateNotNull()]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;#[ValidateNotNullOrEmpty()]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: teal;&quot;&gt;[System.Object]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: orangered;&quot;&gt;$parameterName&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkred;&quot;&gt;&quot;DefaultValue&quot;&lt;/span&gt; &lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt; &lt;/table&gt;&lt;/div&gt;&lt;br /&gt;
Hope that&#39;s helpful!</description><link>http://outputredirection.blogspot.com/2010/02/snippets-for-comment-based-help-and.html</link><author>noreply@blogger.com (v(^_^)v - Clint)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1555090447439276032.post-7743084612733112485</guid><pubDate>Thu, 11 Feb 2010 17:44:00 +0000</pubDate><atom:updated>2010-02-11T09:49:06.185-08:00</atom:updated><title>Using Powershell to search XML GPO Reports – Part II – Software Installation</title><description>In &lt;a href=&quot;http://outputredirection.blogspot.com/2010/01/using-powershell-to-search-for-group.html&quot; target=&quot;_blank&quot;&gt;Part I&lt;/a&gt; of our series in querying group policy reports, we learned how to:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Turn the XML output from Get-GPOReport into a System.XML.XMLDocument object&lt;/li&gt;
&lt;li&gt;Build a System.XML.XMLNamespaceManager from the information in the XMLDocument object&lt;/li&gt;
&lt;li&gt;Use XPath with the namespace manager and document to extract information from the report, including the Extension elements.&lt;/li&gt;
&lt;/ul&gt;We left off with the Get-CGPOReportExtensionData filter, and some questions about it’s output.&amp;nbsp; This week we’ll look at the output from the filter, and then use that output in another filter to transform the XML report information into an object with the details of a Software Installation extension that can easily be worked with using Powershell’s standard comparison operators and formatting cmdlets.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
First, let’s examine the output of Get-CGPOReportExtensionData.&amp;nbsp; When output to the console it looks like:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;fullReport&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : #document     &lt;br /&gt;
extensionNamespaceURI&amp;nbsp; : &lt;/span&gt;&lt;a href=&quot;http://www.microsoft.com/GroupPolicy/Settings/SoftwareInstallation&quot;&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;http://www.microsoft.com/GroupPolicy/Settings/SoftwareInstallation&lt;/span&gt;&lt;/a&gt;    &lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;namespaceMgr&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : {e, q1, , xml...}     &lt;br /&gt;
extensionNamespaceName : q1      &lt;br /&gt;
extensionData&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Extension      &lt;br /&gt;
GPOName&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; : apps-Publisher&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Lets go through what each of these are.&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;‘FullReport’ is the XMLDocument object built from the XML output of Get-GPOReport that we found matching extension information in.&amp;nbsp; This is useful in the event that we want to extract information about the group policy object itself.&amp;nbsp; &lt;/li&gt;
&lt;li&gt;‘ExtensionNamespaceURI’ is the URI for the namespace that we need in order to use XPath queries to extract information from the extension element.&amp;nbsp; &lt;/li&gt;
&lt;li&gt;‘ExtensionNamespaceName’ is the namespace name for the same thing.&amp;nbsp; The namespace name is important as we have to use it in the XPath queries we build later on, the URI somewhat less so but I included it just for the sake of the completion compulsion I had at the time I wrote it.&amp;nbsp; &lt;/li&gt;
&lt;li&gt;‘NamespaceMgr’ is an XMLNamespaceManager object that, because there are namespace declarations in the XMLDocument, is necessary to be able to use the methods of the XML classes that accept XPath queries. &lt;/li&gt;
&lt;li&gt;‘ExtensionData’ is the extension XMLNode that matched the ‘-extensionName’ parameter of Get-CGPOReportExtensionData.&amp;nbsp; It will prove quite useful to use in our XPath queries later.&lt;/li&gt;
&lt;li&gt;‘GPOName’ is the name of the group policy object that contains the matching extension data.&amp;nbsp; Pretty straightforward stuff.&lt;/li&gt;
&lt;/ul&gt;The only information we didn’t cover generating in the last part of this series is the extensionNamespaceURI and extensionNamespaceName, so let’s quickly cover that.&amp;nbsp; The group policy folks were kind enough to make the namespace URI suffix for each extension the same as the extension’s name, without any spaces.&amp;nbsp; So generating that from the extension name that we’re looking for is pretty straightforward:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $extensionURISuffix = $extensionName -replace &quot; &quot;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Armed with that information we can generate the URI and use a method of the XMLElement, ‘GetPrefixOfNamespace’, to get the namespace prefix…which I now realize I have been calling the namespace name.&amp;nbsp; Oops, gonna have to fix that. Anyway:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Get the extension specific namespace name     &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; $extensionNamespaceURI&amp;nbsp; = &quot;&lt;/span&gt;&lt;a href=&quot;http://www.microsoft.com/GroupPolicy/Settings/&quot;&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;http://www.microsoft.com/GroupPolicy/Settings/&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;$extensionURISuffix&quot;     &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; $extensionNamespaceName = $extension.GetPrefixOfNamespace($extensionNamespaceURI)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
And that’s about it for the basic information about the group policy object down to the extension.&amp;nbsp; So now let’s dig into our first extension, Software Installation, in some detail.&amp;nbsp; Don’t forget to download the &lt;a href=&quot;http://sites.google.com/site/outputredirectionfilehosting/clint.gputilities.psm1&quot;&gt;updated module code&lt;/a&gt; and save it as a module (&amp;lt;moduleFolder&amp;gt;\clint.gputilities\clint.gputilities.psm1), and to import it into your Powershell session (Import-Module clint.gputilities) as well as importing the grouppolicy module.&amp;nbsp; First, let’s get some output from our first filter to work with:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS &amp;gt; $swiExtensions = Get-GPOReport –All –ReportType XML | Get-CGPOReportExtensionData –ExtensionName “Software Installation”     &lt;br /&gt;
PS &amp;gt; $e = $swiExtensions[0]&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
At this point we should have an object, $e, that we can dig into.&amp;nbsp; But to dig into it we need the namespace manager, how handy that it’s right there for the picking:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS &amp;gt; $nsMgr = $e.namespaceMgr&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Yeah, we could just use $e.namespaceMgr all the time but that’s kind of a pain.&amp;nbsp; Next we need the namespace prefix in order to use XPath to dig into the extension information.&amp;nbsp; I promise I’ll fix the variable name by next part in the series…&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS &amp;gt; $ns = $e.extensionNamespaceName&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Alright, now we can start digging.&amp;nbsp; Each software installation element can contain multiple package child elements.&amp;nbsp; We only use MSI packages here, so that’s what we’ll be looking at, but if someone has an XML report for one of the few other types of installation packages I’d be glad to incorporate those.&amp;nbsp; Let’s gather the MsiApplication nodeset:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS &amp;gt; $msiNodes = $e.extensionData.SelectNodes(“./$ns`:MsiApplication”,$nsMgr)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
There are a few things to note here.&amp;nbsp; First, that we finally put the namespace prefix ($ns) from our extension data to use.&amp;nbsp; Second, that we have to use the Powershell escape character ‘`’ before the colon following the namespace prefix variable.&amp;nbsp; Why?&amp;nbsp; Because of the way variables can be addressed.&amp;nbsp; For instance, when we want to check the username environment variable we use:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS &amp;gt; $env:username&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The ‘:’ says, “Go to the env psdrive, and select the username childitem”.&amp;nbsp; So the statement is generally ‘$PSDrive:ChildItem’.&amp;nbsp; So then this has implications when we use variable expansion inside of a string.&amp;nbsp; Continuing the username environment variable example, if we wanted to include it inside of a string we can use multiple methods:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS &amp;gt; “My username is:&amp;nbsp; “ + $env:username     &lt;br /&gt;
PS &amp;gt; “My username is:&amp;nbsp; {0}” –f $env:username      &lt;br /&gt;
PS &amp;gt; “My username is:&amp;nbsp; $env:username”&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The same string will be produced in all three cases, “&lt;span style=&quot;font-family: Courier New;&quot;&gt;My username is: clint&lt;/span&gt;”.&amp;nbsp; See the potential problem with our XPath string?&amp;nbsp; We need Powershell to recognize that the namespace prefix is followed by a &lt;b&gt;literal&lt;/b&gt; colon, otherwise it’s going to go looking for a psdrive with the name of our namespace prefix, and probably come up with nothing.&amp;nbsp; So we use the ‘`’ escape character to tell Powershell the colon is literal and our XPath queries work.&amp;nbsp; That diversion aside, next we’ll select the first child node in the event that there are more than one MsiApplication elements:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS &amp;gt; $m = $msiNodes.item(0)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Now let’s look at how $m is presented by the console’s output:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS &amp;gt; $m&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;Identifier&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : {297a8ec5-2e10-49ed-931e-90d7cef549cb}     &lt;br /&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;&amp;nbsp;&amp;nbsp; : Microsoft Publisher 2002      &lt;br /&gt;
Path&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; : \\server\share\MS Publisher 2002\PUB.MSI      &lt;br /&gt;
MajorVersion&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 10      &lt;br /&gt;
MinorVersion&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 0      &lt;br /&gt;
LanguageId&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 1033      &lt;br /&gt;
Architecture&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : 0      &lt;br /&gt;
…&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Hey, easy from here, we’re done…right?&amp;nbsp; Not quite.&amp;nbsp; Yes, the way Powershell surfaces XML objects can make them a bit easier to work with, but it does have its flaws and starts to break down as noted in &lt;a href=&quot;http://www.pluralsight.com/community/blogs/dan/archive/2006/11/25/42506.aspx&quot;&gt;Processing XML with PowerShell&lt;/a&gt;.&amp;nbsp; So let’s use the XML object itself to create a custom PSObject that fits our needs and that we can re-use down the pipe.&amp;nbsp; There are essentially two types of XMLNodes in $m, those that only contain a single XmlText node, and those that contain other elements.&amp;nbsp; The elements that only contain a single XmlText node are the easiest to create a property from.&amp;nbsp; Let’s take ‘Identifier’ as an example:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS &amp;gt; $m.SelectSingleNode(&quot;./$ns`:Identifier&quot;,$nsMgr).InnerText     &lt;br /&gt;
{297a8ec5-2e10-49ed-931e-90d7cef549cb}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
That’s not too tough.&amp;nbsp; Which is good, because there’s a lot of those nodes in the MsiApplication node.&amp;nbsp; The nodes that contain other element nodes are more complicated to turn into properties directly, most notably the SecurityDescriptor element (which we won’t tackle yet), but this can be accomplished using script blocks.&amp;nbsp; Let’s take ‘Upgrades’ as our example this time.&amp;nbsp; The XML itself it looks like:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;&amp;lt;q2:Upgrades&amp;gt;     &lt;br /&gt;
&amp;nbsp; &amp;lt;q2:Mandatory&amp;gt;true&amp;lt;/q2:Mandatory&amp;gt;      &lt;br /&gt;
&amp;nbsp; &amp;lt;q2:PackageInfo&amp;gt;      &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;q2:GPOIdentifier&amp;gt;      &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Identifier xmlns=&quot;&lt;/span&gt;&lt;a href=&quot;http://www.microsoft.com/GroupPolicy/Types%22&quot;&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;http://www.microsoft.com/GroupPolicy/Types&quot;&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;&amp;gt;{7A2F01E5-895E-4029-AC3D-9F478DB4DEA7}&amp;lt;/Identifier&amp;gt;     &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Domain xmlns=&quot;&lt;/span&gt;&lt;a href=&quot;http://www.microsoft.com/GroupPolicy/Types%22%3Edomain.com%3C/Domain&quot;&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;domain.comhttp://www.microsoft.com/GroupPolicy/Types&quot;&amp;gt;domain.com&amp;lt;/Domain&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;&amp;gt;     &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/q2:GPOIdentifier&amp;gt;      &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;q2:GPOName&amp;gt;adm-WorkStations&amp;lt;/q2:GPOName&amp;gt;      &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;q2:Name&amp;gt;Microsoft Office XP Professional&amp;lt;/q2:Name&amp;gt;      &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;q2:Identifier&amp;gt;{45b72218-66bf-41e0-beeb-881eab80dd31}&amp;lt;/q2:Identifier&amp;gt;      &lt;br /&gt;
&amp;nbsp; &amp;lt;/q2:PackageInfo&amp;gt;      &lt;br /&gt;
&amp;lt;/q2:Upgrades&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
So here the ‘Mandatory’ element should be simple enough to extract, in fact in our module I decided to break it out into it’s own property, UpgradesMandatory.&amp;nbsp; To get at it is fairly straightforward:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS &amp;gt; $m.SelectSingleNode(&quot;./$ns`:Upgrades/$ns`:Mandatory&quot;,$nsMgr).InnerText&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
However, there can be multiple ‘PackageInfo’ elements under ‘Upgrades’, so we need a little more power to turn that into a property that’s complete and easy to work with.&amp;nbsp; I chose to create a PSObject array and add properties to each object that reflect the data contained in GPOIdentifier, GPOName, Name, and Identifier.&amp;nbsp; Though the following code isn’t complete yet, it will be soon and gets the idea across:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;[PSObject[]]$arrUpgrades = @()     &lt;br /&gt;
foreach ($p in $m.SelectNodes(&quot;./$ns`:Upgrades/$ns`:PackageInfo&quot;,$namespaceMgr))      &lt;br /&gt;
{      &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; $arrUpgrades += New-Object PSObject -Property @{      &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GPOIdentifier = $null #TODO: Get GPOIdentifier      &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GPODomain&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; = $null #TODO: Get GPODomain      &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GPOName&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; = $p.SelectSingleNode(&quot;./$ns`:GPOName&quot;,$namespaceMgr).InnerText      &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 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;&amp;nbsp;&amp;nbsp; = $p.SelectSingleNode(&quot;./$ns`:Name&quot;,$namespaceMgr).InnerText      &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Identifier&amp;nbsp;&amp;nbsp;&amp;nbsp; = $p.SelectSingleNode(&quot;./$ns`:Identifier&quot;,$namespaceMgr).InnerText      &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }      &lt;br /&gt;
}      &lt;br /&gt;
Write-Output $arrUpgrades&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
We can follow a similar pattern to create objects from other complex nodes.&amp;nbsp; So, big deal, what can we do now?&amp;nbsp; Just had a use for this yesterday, in fact.&amp;nbsp; We’re working on migrating most of our software distribution from Group Policy to System Center Configuration Manager and needed to know what software was being installed through Group Policy.&amp;nbsp; So using this module we were easily able to produce that info with:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS &amp;gt; Get-CGPOReportSoftwareInstallationData | Select-Object name,majorversion,minorversion –unique | Format-Table name,majorversion,minorversion –auto     &lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&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;&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; MajorVersion MinorVersion     &lt;br /&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ------------ ------------      &lt;br /&gt;
Microsoft Publisher 2002&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; 10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0      &lt;br /&gt;
Microsoft Office XP Professional&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0      &lt;br /&gt;
Microsoft Office Professional Edition 2003&amp;nbsp; 11&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0      &lt;br /&gt;
Sun Java Runtime Environment&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; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Now that I’ve been working on this little project for a few weeks off and on, I’m thinking about reworking the filters a bit for workflow reasons.&amp;nbsp; So the next time we see this module it will be a little bit different, but all the guts of working with the XML remain the same.&amp;nbsp; The next entry in the series we will at least complete extracting the SecurityDescriptor information, but I’m sure I’ll get more work done on this than that.&amp;nbsp; The current version of the module is below.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://sites.google.com/site/outputredirectionfilehosting/clint.gputilities.psm1&quot;&gt;&amp;nbsp;Download clint.gputilities.psm1&lt;/a&gt;</description><link>http://outputredirection.blogspot.com/2010/02/using-powershell-to-search-xml-gpo.html</link><author>noreply@blogger.com (v(^_^)v - Clint)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1555090447439276032.post-7238344055943361144</guid><pubDate>Mon, 01 Feb 2010 18:17:00 +0000</pubDate><atom:updated>2010-02-01T10:20:30.030-08:00</atom:updated><title>Get the users that have logged on to a computer</title><description>Here’s a multi-line adaptation of a quick one-liner I threw together the other day.&amp;nbsp; I might have to turn this into a function and add it to my profile if I get asked this question too many more times.&amp;nbsp; To answer “Who used computer x between these dates?” we can use:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 700px;&quot;&gt;&lt;table border=&quot;0&quot; cellpadding=&quot;5&quot; cellspacing=&quot;0&quot; unselectable=&quot;on&quot;&gt;&lt;tbody&gt;
&lt;tr&gt; &lt;td valign=&quot;top&quot;&gt;&lt;div style=&quot;background: none repeat scroll 0% 0% rgb(206, 206, 206); font-family: Consolas,Lucida Console; font-size: 10pt; padding: 5px;&quot;&gt;001&lt;br /&gt;
002&lt;br /&gt;
003&lt;br /&gt;
004 &lt;br /&gt;
005&lt;br /&gt;
006&lt;br /&gt;
007 &lt;/div&gt;&lt;/td&gt; &lt;td nowrap=&quot;nowrap&quot; valign=&quot;top&quot;&gt;&lt;div style=&quot;background: none repeat scroll 0% 0% rgb(252, 252, 252); font-family: Consolas,Lucida Console; font-size: 10pt; padding: 5px;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;Get-EventLog&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;-Before&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkred;&quot;&gt;&#39;01/26/2010&#39;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;-after&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkred;&quot;&gt;&#39;01/25/2010&#39;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;-ComputerName&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: blueviolet;&quot;&gt;computername&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;-LogName&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blueviolet;&quot;&gt;Security&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;`&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;where-object&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;`&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$_&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;username&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;-notmatch&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkred;&quot;&gt;&#39;^NT  AUTHORITY\\(SYSTEM|NETWORK SERVICE|LOCAL SERVICE|ANONYMOUS LOGON)$&#39;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;`&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgrey;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -and&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$_&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;category&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;-eq&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkred;&quot;&gt;&quot;Logon/Logoff&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;`&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;select-object&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blueviolet;&quot;&gt;timegenerated&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: blueviolet;&quot;&gt;username&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: blueviolet;&quot;&gt;category&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: blueviolet;&quot;&gt;message&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;sort&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blueviolet;&quot;&gt;timegenerated&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;format-table&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;-auto&lt;/span&gt;  &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;br /&gt;
Hope that can save some of you a little time :)</description><link>http://outputredirection.blogspot.com/2010/02/get-users-that-have-logged-on-to.html</link><author>noreply@blogger.com (v(^_^)v - Clint)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1555090447439276032.post-2362692247203183001</guid><pubDate>Mon, 01 Feb 2010 17:57:00 +0000</pubDate><atom:updated>2010-02-01T09:57:27.464-08:00</atom:updated><title>BackTrack 4 Final Now Available</title><description>&lt;p&gt;I’m a little behind the curve here, as the final build was posted on the 11th of January.&amp;#160; Oh well.&amp;#160; For the security conscious administrator, the backtrack suite makes a great tool.&amp;#160; If you don’t know what it is, or taken the time to at least check it out, cut some time out to do so soon.&amp;#160; It will open your eyes a bit, I promise :)&lt;/p&gt;  &lt;p&gt;The final build, available in either .ISO or VM-ware forms, can be downloaded from &lt;a title=&quot;http://www.backtrack-linux.org/downloads/&quot; href=&quot;http://www.backtrack-linux.org/downloads/&quot;&gt;http://www.backtrack-linux.org/downloads/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;If you can, use the torrent links.&amp;#160; Your download will most likely be much faster.&lt;/p&gt;  </description><link>http://outputredirection.blogspot.com/2010/02/backtrack-4-final-now-available.html</link><author>noreply@blogger.com (v(^_^)v - Clint)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1555090447439276032.post-3839629537831738071</guid><pubDate>Fri, 29 Jan 2010 20:01:00 +0000</pubDate><atom:updated>2010-01-30T16:17:33.530-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">group policy</category><category domain="http://www.blogger.com/atom/ns#">Powershell</category><category domain="http://www.blogger.com/atom/ns#">XML</category><title>Using PowerShell to search Group Policy XML Reports</title><description>I was going to write about creating, editing, and saving XML files using the System.XML objects today but discovered it had been covered quite well already after a quick Google search.&amp;nbsp; So instead we’ll jump ahead a little bit and use PowerShell &amp;amp; .NET’s XML capabilities to dive into the GPO Reports that can be generated using Get-GPOReport from the grouppolicy module.&lt;br /&gt;
&lt;br /&gt;
This will be the first in a small series of posts that should end up with us having a module capable of searching for any group policy setting that is recorded in the XML reports.&amp;nbsp; That’s the goal, but I’m posting as I get things 90% complete so hopefully all this proves useful and you’ll be willing to bear with me.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
Before that, if you need a little XML for PowerShell primer, I suggest giving these posts a read first:&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.pluralsight.com/community/blogs/dan/archive/2006/11/25/42506.aspx&quot; title=&quot;http://www.pluralsight.com/community/blogs/dan/archive/2006/11/25/42506.aspx&quot;&gt;Processing XML with PowerShell&lt;/a&gt; &lt;br /&gt;
&lt;a href=&quot;http://www.pluralsight.com/community/blogs/dan/archive/2006/11/28/43561.aspx&quot; title=&quot;http://www.pluralsight.com/community/blogs/dan/archive/2006/11/28/43561.aspx&quot;&gt;Processing XML with PowerShell II&lt;/a&gt; &lt;br /&gt;
&lt;a href=&quot;http://powershell.com/cs/blogs/tobias/archive/2009/01/17/xml-part-1-playing-with-rss-feeds-and-xml-content.aspx&quot; title=&quot;http://powershell.com/cs/blogs/tobias/archive/2009/01/17/xml-part-1-playing-with-rss-feeds-and-xml-content.aspx&quot;&gt;XML Part 1: Playing with RSS Feeds and XML Content&lt;/a&gt; &lt;br /&gt;
&lt;a href=&quot;http://powershell.com/cs/blogs/tobias/archive/2009/02/02/xml-part-2-write-add-and-change-xml-data.aspx&quot; title=&quot;http://powershell.com/cs/blogs/tobias/archive/2009/02/02/xml-part-2-write-add-and-change-xml-data.aspx&quot;&gt;XML Part 2: Write, Add And Change XML Data&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
With the basics out of the way, onto the fun!&amp;nbsp; Well, OK, not quite yet.&amp;nbsp; First the requirements:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Windows 7 or Server 2008 R2 with the RSAT installed &lt;/li&gt;
&lt;/ul&gt;That was easy.&amp;nbsp; The first thing we’ll need to do is import the grouppolicy module.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS C:\&amp;gt; import-module grouppolicy&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
But, without a group policy report to work with we’re not much of anywhere so let’s get a collection of all our reports ( probably not a good idea if you have thousands of GPOs, you’ll have to fend for yourselves ), then pick the first one to inspect.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS C:\&amp;gt; $allGPOReports = Get-GPOReport –All –ReportType XML&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS C:\&amp;gt; $GPOReport = $allGPOReports[0]&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
If we inspect $GPOReport through it’s GetType() method we’ll see that it’s just a string at the moment.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS C:\&amp;gt; $gporeport.gettype() | ft -auto &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;IsPublic IsSerial Name&amp;nbsp;&amp;nbsp; BaseType&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
-------- -------- ----&amp;nbsp;&amp;nbsp; --------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
True&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; True&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; String System.Object&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
It’s a really long string, but a string nonetheless.&amp;nbsp; Let’s do a couple of things to get a good look at it.&amp;nbsp; First we’ll dump it to a file so we can open it in our favorite XML viewer/editor.&amp;nbsp; Then we’ll create a System.XML.XMLDocument object to work with in PowerShell.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS C:\&amp;gt; out-file -InputObject $GPOReport -FilePath C:\Temp\gporeport.xml&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS C:\&amp;gt; $xmlReport = New-Object system.xml.xmldocument&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS C:\&amp;gt; $xmlReport.LoadXml($GPOReport)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
I’ve been working with a few different XML editors lately and I think I’ve settled on &lt;a href=&quot;http://www.oxygenxml.com/&quot; target=&quot;_blank&quot;&gt;&amp;lt;oXygen/&amp;gt; XML Editor&lt;/a&gt; but we’re still in our trial period, so we’ll see.&amp;nbsp; If you don’t have access to an XML IDE, then something like &lt;a href=&quot;http://notepad-plus.sourceforge.net/uk/site.htm&quot; target=&quot;_blank&quot;&gt;NotePad++&lt;/a&gt; is a great alternative.&amp;nbsp; Anything with syntax highlighting and code folding for XML will prove handy, however.&amp;nbsp; Once you have the gporeport.xml file open, let’s look at the second line:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;&amp;lt;GPO xmlns:xsi=&quot;&lt;/span&gt;&lt;a href=&quot;http://www.w3.org/2001/XMLSchema-instance%22&quot;&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;http://www.w3.org/2001/XMLSchema-instance&quot;&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt; xmlns:xsd=&quot;&lt;/span&gt;&lt;a href=&quot;http://www.w3.org/2001/XMLSchema%22&quot;&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;http://www.w3.org/2001/XMLSchema&quot;&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt; xmlns=&quot;&lt;/span&gt;&lt;a href=&quot;http://www.microsoft.com/GroupPolicy/Settings%22&quot;&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;http://www.microsoft.com/GroupPolicy/Settings&quot;&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
We’re going to need those namespace declarations in order to query our report for anything, so lets setup a namespace manager with the proper information. First we’ll get the collection of namespaces declared in the line above, then populate the namespace manager with those.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS C:\&amp;gt; $nsMgr = New-Object System.Xml.XmlNamespaceManager $xmlReport.CreateNavigator().NameTable&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS C:\&amp;gt; $namespaces = $xmlReport.CreateNavigator().GetNamespacesInScope(&#39;All&#39;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS C:\&amp;gt; foreach ($key in $namespaces.keys) { $nsMgr.AddNamespace( $key, $namespaces.$key ) }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS C:\&amp;gt; $nsmgr.AddNamespace( &quot;e&quot;, $nsmgr.DefaultNamespace )&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Why that last line?&amp;nbsp; The short of it is we have to prefix anything in the XML document in the default namespace with a named namespace in order for .NET to find it.&amp;nbsp; The long version is in the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/aa335968%28VS.71%29.aspx&quot; target=&quot;_blank&quot;&gt;MSDN docs&lt;/a&gt;.&amp;nbsp; I call mine “e” because it’s easy to type.&amp;nbsp; You can pick whatever you want as long as it doesn’t collide with other namespaces in the document.&amp;nbsp; Okay, so now we have a System.Xml.XMLDocument object to search, and &lt;i&gt;most&lt;/i&gt; of the namespaces we need.&amp;nbsp; Most?&amp;nbsp; Yep, &lt;i&gt;most&lt;/i&gt;.&amp;nbsp; But we’ll tackle that later.&amp;nbsp; For now, let’s see what we get looking for an extension.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS C:\&amp;gt; $xmlReport.SelectNodes( &quot;//e:ExtensionData&quot;, $nsMgr ) | ft -auto &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;Extension 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;&amp;nbsp; &lt;br /&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; &lt;br /&gt;
Extension Security&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
Extension Public Key&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
Extension Registry&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
Extension Remote Installation&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Hey!&amp;nbsp; We got results, awesome!&amp;nbsp; Yours probably look different than mine, but that’s OK.&amp;nbsp; So now with just a little work and a little XPATH know-how, we can look inside of our GPO reports for extensions, and a whole lot more.&amp;nbsp; Last Modification Time when the report was run?&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS C:\&amp;gt; [datetime]($xmlReport.SelectSingleNode( &quot;/e:GPO/e:ModifiedTime&quot;, $nsMgr ).&#39;#text&#39;) &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;Friday, September 04, 2009 4:16:13 PM&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Where was this GPO linked to when this report was generated?&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS C:\&amp;gt; $xmlReport.SelectNodes( &quot;/e:GPO//e:LinksTo&quot;, $nsMgr ) | ft -auto &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;SOMName&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SOMPath&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;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Enabled NoOverride &lt;br /&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;&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;br /&gt;
Aaron-PC&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; domain.org/00-hardware/WorkStations/ADM/ws/Aaron-PC true&amp;nbsp;&amp;nbsp;&amp;nbsp; false&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
projectorPCs domain.org/00-hardware/WorkStations/projectorPCs&amp;nbsp;&amp;nbsp;&amp;nbsp; true&amp;nbsp;&amp;nbsp;&amp;nbsp; false&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
psd267&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; domain.org&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;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; true&amp;nbsp;&amp;nbsp;&amp;nbsp; false&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Which of our GPO reports have configuration for the “Files” extension?&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS C:\&amp;gt; $allGPOReports | Get-CGPOReportExtensionData -extensionName &quot;Files&quot; &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;fullReport&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : #document &lt;br /&gt;
extensionNamespaceURI&amp;nbsp; : &lt;/span&gt;&lt;a href=&quot;http://www.microsoft.com/GroupPolicy/Settings/Files&quot;&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;http://www.microsoft.com/GroupPolicy/Settings/Files&lt;/span&gt;&lt;/a&gt; &lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;extensionNamespaceName : q4 &lt;br /&gt;
extensionData&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Extension &lt;br /&gt;
GPOName&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; : DriveMaps_Files_Folders_Shortcuts &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;fullReport&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : #document &lt;br /&gt;
extensionNamespaceURI&amp;nbsp; : &lt;/span&gt;&lt;a href=&quot;http://www.microsoft.com/GroupPolicy/Settings/Files&quot;&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;http://www.microsoft.com/GroupPolicy/Settings/Files&lt;/span&gt;&lt;/a&gt; &lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;extensionNamespaceName : q1 &lt;br /&gt;
extensionData&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : Extension &lt;br /&gt;
GPOName&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; : apps-Deploy-Audacity&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Hey, what the, where did “Get-CGPOReportExtensionData” come from?&amp;nbsp; And what’s with the q1/q4 namespace junk?&amp;nbsp; Get-CGPOReportExtensionData is the first function in our module we’re working on.&amp;nbsp; No doubt it will evolve over the next few weeks as we snorkel around (I leave the deep diving to the pros and MVPs) in the XML reports, in fact I found a better way to extract namespace info from the extensions while I wrote this post, though I haven&#39;t updated the module with it yet. &amp;nbsp; The code for the module is below.&amp;nbsp; Just save it as &quot;clint.gputilities.psm1&quot; in one of your module folders in a subdirectory called “clint.gputilities” and then import it into your PowerShell session to start using it.&amp;nbsp; Hopefully we can come up with a better name by the time we’re done.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Courier New;&quot;&gt;PS C:\&amp;gt; Import-Module clint.gputilities&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Next week we’ll refine this filter a bit, and dig into our first extension: Software Installation.&amp;nbsp; See you then!&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;border: 1px solid black; font-family: Consolas,Lucida Console; font-size: 10pt; overflow: auto; padding: 5px; width: 750px;&quot;&gt;&lt;table border=&quot;0&quot; cellpadding=&quot;5&quot; cellspacing=&quot;0&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;     &lt;td valign=&quot;Top&quot;&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(206, 206, 206) none repeat scroll 0% 0%; font-family: Consolas,Lucida Console; font-size: 10pt; padding: 5px;&quot;&gt;001&lt;br /&gt;
002&lt;br /&gt;
003&lt;br /&gt;
004&lt;br /&gt;
005&lt;br /&gt;
006&lt;br /&gt;
007&lt;br /&gt;
008&lt;br /&gt;
009&lt;br /&gt;
010&lt;br /&gt;
011&lt;br /&gt;
012&lt;br /&gt;
013&lt;br /&gt;
014&lt;br /&gt;
015&lt;br /&gt;
016&lt;br /&gt;
017&lt;br /&gt;
018&lt;br /&gt;
019&lt;br /&gt;
020&lt;br /&gt;
021&lt;br /&gt;
022&lt;br /&gt;
023&lt;br /&gt;
024&lt;br /&gt;
025&lt;br /&gt;
026&lt;br /&gt;
027&lt;br /&gt;
028&lt;br /&gt;
029&lt;br /&gt;
030&lt;br /&gt;
031&lt;br /&gt;
032&lt;br /&gt;
033&lt;br /&gt;
034&lt;br /&gt;
035&lt;br /&gt;
036&lt;br /&gt;
037&lt;br /&gt;
038&lt;br /&gt;
039&lt;br /&gt;
040&lt;br /&gt;
041&lt;br /&gt;
042&lt;br /&gt;
043&lt;br /&gt;
044&lt;br /&gt;
045&lt;br /&gt;
046&lt;br /&gt;
047&lt;br /&gt;
048&lt;br /&gt;
049&lt;br /&gt;
050&lt;br /&gt;
051&lt;br /&gt;
052&lt;br /&gt;
053&lt;br /&gt;
054&lt;br /&gt;
055&lt;br /&gt;
056&lt;br /&gt;
057&lt;br /&gt;
058&lt;br /&gt;
059&lt;br /&gt;
060&lt;br /&gt;
061&lt;br /&gt;
062&lt;br /&gt;
063&lt;br /&gt;
064&lt;br /&gt;
065&lt;br /&gt;
066&lt;br /&gt;
067&lt;br /&gt;
068&lt;br /&gt;
069&lt;br /&gt;
070&lt;br /&gt;
071&lt;br /&gt;
072&lt;br /&gt;
073&lt;br /&gt;
074&lt;br /&gt;
075&lt;br /&gt;
076&lt;br /&gt;
077&lt;br /&gt;
078&lt;br /&gt;
079&lt;br /&gt;
080&lt;br /&gt;
081&lt;br /&gt;
082&lt;br /&gt;
083&lt;br /&gt;
084&lt;br /&gt;
085&lt;br /&gt;
086&lt;br /&gt;
087&lt;br /&gt;
088&lt;br /&gt;
089&lt;br /&gt;
090&lt;br /&gt;
091&lt;br /&gt;
092&lt;br /&gt;
093&lt;br /&gt;
094&lt;br /&gt;
095&lt;br /&gt;
096&lt;br /&gt;
097&lt;br /&gt;
098&lt;br /&gt;
099&lt;br /&gt;
100&lt;br /&gt;
101&lt;br /&gt;
102&lt;br /&gt;
103&lt;/div&gt;&lt;/td&gt;     &lt;td nowrap=&quot;NOWRAP&quot; valign=&quot;Top&quot;&gt;&lt;div style=&quot;-moz-background-clip: border; -moz-background-inline-policy: continuous; -moz-background-origin: padding; background: rgb(252, 252, 252) none repeat scroll 0% 0%; font-family: Consolas,Lucida Console; font-size: 10pt; padding: 5px;&quot;&gt;&lt;span style=&quot;color: darkblue;&quot;&gt;filter&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blueviolet;&quot;&gt;Get-CGPOReportExtensionData&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;&amp;lt;#   .SYNOPSIS&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;&amp;nbsp;    Queries XML Reports generated by Get-GPOReport for specific Extension information&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;.DESCRIPTION&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;&amp;nbsp; Finds the extension specified by the parameter ExtensionName in the     Report or Reports&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;&amp;nbsp; (i.e. Files, Registry, Software Installation).  Tacks on     the namespace information&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;&amp;nbsp; necessary to query the extension onto the report     as a custom PSObject and writes that&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;&amp;nbsp; information to output.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;.PARAMETER gpoReport&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;&amp;nbsp; A report generated by Get-GPOReport -reportType XML.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;.PARAMETER namespaceMgr&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;&amp;nbsp; If no namespace manager is assigned to this value, the default    namespaces for group&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;&amp;nbsp; policy XML reports are used.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;.PARAMETER extensionName&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;&amp;nbsp; The name of the group policy extension that you wish to find in the reports.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;&amp;nbsp; Valid names I am currently aware of:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Security,Public Key,Registry,Remote Installation,Internet Explorer Maintenance,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Software Installation,Scripts,Folder Redirection,Printers,Windows Firewall,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Software Restriction,Drive Maps,Shortcuts,Folders,Files,Windows Registry,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Environment Variables,WLanSvc Networks,Folder Options,Start Menu,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Deployed Printer Connections Policy,Ini Files&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;.EXAMPLE&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;&amp;nbsp; Get-GPOReport -All -ReportType XML | Get-CGPOReportExtension Data -ExtensionName &quot;Drive Maps&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;.INPUTS&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;&amp;nbsp; [System.XML.XMLDocument]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;.OUTPUTS&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;&amp;nbsp; [System.Management.Automation.PSCustomObject]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;.NOTES&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;&amp;nbsp; Todo.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;.FUNCTIONALITY&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt;&amp;nbsp; Todo.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: darkgreen;&quot;&gt; #&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;#region cmdletbinding&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: lightblue;&quot;&gt;CmdletBinding&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;#endregion&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;#region parameters&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkblue;&quot;&gt;param&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: lightblue;&quot;&gt;parameter&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;Mandatory&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$true&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;ValueFromPipeline&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$true&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;[Xml.XmlDocument]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$gpoReport&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: lightblue;&quot;&gt;parameter&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;Mandatory&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$false&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;[Xml.XmlNamespaceManager]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$namespaceMgr&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: lightblue;&quot;&gt;parameter&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;Mandatory&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$true&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;[String]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$extensionName&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;#endregion&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkblue;&quot;&gt;process&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;# Build a namespace manager if we don&#39;t have one&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: darkblue;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;-not&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$namespaceMgr&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;   &lt;/span&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;# Create a namespace manager from our navigator object&#39;s nametable&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;   &lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$namespaceMgr&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;New-Object&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blueviolet;&quot;&gt;System.Xml.XmlNamespaceManager&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$gpoReport&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;CreateNavigator&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;NameTable&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;   &lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$namespaceMgr&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;AddNamespace&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: darkred;&quot;&gt;&quot;e&quot;&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkred;&quot;&gt;&quot;http://www.microsoft.com/GroupPolicy/Settings&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;# We&#39;re going to cheat and use Posh&#39;s dotted notation to get the GPO name&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;# there is only one GPO node (it&#39;s the root), and only one Name element&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$GPOName&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$gpoReport&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;GPO&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;Name&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;# Gather the Extensions that match the our queryCSE&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$extensions&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$gpoReport&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;selectnodes&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: darkred;&quot;&gt;&quot;/e:GPO//e:ExtensionData[e:Name = &#39;$extensionName&#39;]/e:Extension&quot;&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$namespaceMgr&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkblue;&quot;&gt;foreach&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$extension&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkblue;&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$extensions&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;# Init the extension specific namespace variable&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$extensionNamespaceName&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$null&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$extensionNamespaceURI&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$null&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;# We need the Extension child element of this ExtensionData element&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;# and have to extract the specific namespaces assigned for Extension&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;# by the &#39;Get-GPOReport&#39; cmdlet&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$eNavigator&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$extension&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;CreateNavigator&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$eNamespace&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$eNavigator&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;GetNamespacesInScope&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: darkred;&quot;&gt;&#39;All&#39;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: darkblue;&quot;&gt;foreach&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$key&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkblue;&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$eNamespace&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;keys&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;# The namespace assignments we&#39;re looking for are always named &#39;q1&#39;, &#39;q2&#39;, ... &#39;q99&#39;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;# If there&#39;s more than a hundred, someone needs to start splitting up their GPOs, :)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: darkblue;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$key&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;-match&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkred;&quot;&gt;&#39;^q\d{1,2}$&#39;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &lt;/span&gt;&lt;span style=&quot;color: darkgreen;&quot;&gt;# Now we have the namespace assignment that is valid to query this element&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$gpoExtInfo&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;New-Object&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blueviolet;&quot;&gt;PSObject&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: navy;&quot;&gt;-Property&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;@{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;           &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;GPOName&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$GPOName&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;           &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;fullReport&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;   &lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$gpoReport&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;           &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;extensionData&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$extension&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;           &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;extensionNamespaceName&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$key&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;           &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;extensionNamespaceURI&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$eNamespace&lt;/span&gt;&lt;span style=&quot;color: darkgrey;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$key&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;          &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;Write-Output&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: orangered;&quot;&gt;$gpoExtInfo&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: black;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;Export-ModuleMember&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blueviolet;&quot;&gt;Get-CGPOReportExtensionData&lt;/span&gt; &lt;/div&gt;&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt; &lt;/table&gt;&lt;/div&gt;</description><link>http://outputredirection.blogspot.com/2010/01/using-powershell-to-search-for-group.html</link><author>noreply@blogger.com (v(^_^)v - Clint)</author></item></channel></rss>