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

<channel>
	<title>Andrew Morgan &#187; PowerShell</title>
	<atom:link href="http://andrewmorgan.ie/tag/powershell/feed/" rel="self" type="application/rss+xml" />
	<link>http://andrewmorgan.ie</link>
	<description>Grumpy ramblings</description>
	<lastBuildDate>Fri, 30 Jun 2017 09:24:25 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.0</generator>
	<item>
		<title>New Module: Creating an RDP file password with PowerShell</title>
		<link>http://andrewmorgan.ie/2015/10/new-module-creating-an-rdp-file-password-with-powershell/</link>
		<comments>http://andrewmorgan.ie/2015/10/new-module-creating-an-rdp-file-password-with-powershell/#comments</comments>
		<pubDate>Mon, 19 Oct 2015 20:23:03 +0000</pubDate>
		<dc:creator><![CDATA[andyjmorgan]]></dc:creator>
				<category><![CDATA[Administration]]></category>
		<category><![CDATA[PowerShell Scripting]]></category>
		<category><![CDATA[Remote Desktop Services (RDS)]]></category>
		<category><![CDATA[Server Based Computing]]></category>
		<category><![CDATA[Module]]></category>
		<category><![CDATA[Password]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[RDP]]></category>
		<category><![CDATA[RDS]]></category>

		<guid isPermaLink="false">http://andrewmorgan.ie/?p=3556</guid>
		<description><![CDATA[Here&#8217;s something that is surprisingly tricky to automate in this day and age. Creating a password and storing it in an RDP file. I&#8217;m not here to debate the security &#8220;knock ons&#8221; of doing this, it&#8217;s not in my interest and if I&#8217;m asked to do something despite advice against it, I do it! But as always I figured I&#8217;d share this feature in case anyone else needs it. So RDP files encrypt a password in a very specific way [&#8230;]]]></description>
				<content:encoded><![CDATA[<p lang="en-GB" style="margin: 0in; font-family: Calibri; font-size: 11.0pt;"><img class="alignright size-thumbnail wp-image-403" src="http://andrewmorgan.ie/wp-content/uploads/2011/03/windows_powershell_icon-150x150.png" alt="Windows_PowerShell_icon" width="150" height="150" />Here&#8217;s something that is surprisingly tricky to automate in this day and age. Creating a password and storing it in an RDP file. I&#8217;m not here to debate the security &#8220;knock ons&#8221; of doing this, it&#8217;s not in my interest and if I&#8217;m asked to do something despite advice against it, I do it!</p>
<p lang="en-GB" style="margin: 0in; font-family: Calibri; font-size: 11.0pt;">But as always I figured I&#8217;d share this feature in case anyone else needs it.</p>
<p lang="en-GB" style="margin: 0in; font-family: Calibri; font-size: 11.0pt;">So RDP files encrypt a password in a very specific way and details online are cagey.This is something I set about doing myself and I&#8217;m happy to annouce I&#8217;ve included it in the following Free Powershell module for your use!</p>
<p lang="en-GB" style="margin: 0in; font-family: Calibri; font-size: 11.0pt;"><span id="more-3556"></span></p>
<h3 lang="en-GB" style="margin: 0in; font-family: Calibri; font-size: 11.0pt;">The module is very simple:</h3>
<p>&nbsp;</p>
<p lang="en-GB" style="margin: 0in; font-family: Calibri; font-size: 11.0pt;">Importing the module:</p>
<pre lang="en-GB" style="margin: 0in; font-family: Calibri; font-size: 11.0pt;">Import-module RDS.Password.dll</pre>
<p lang="en-GB" style="margin: 0in; font-family: Calibri; font-size: 11.0pt;">Converting a string to a password:</p>
<pre lang="en-GB" style="margin: 0in; font-family: Calibri; font-size: 11.0pt;">Get-RDPPassword -Password "SomethingSecure"</pre>
<p lang="en-GB" style="margin: 0in; font-family: Calibri; font-size: 11.0pt;">This will give you an rdp password, pre formatted for an rdp file.</p>
<p lang="en-GB" style="margin: 0in; font-family: Calibri; font-size: 11.0pt;"><a href="http://andrewmorgan.ie/wp-content/uploads/2015/10/rdppassword.png"><img class="aligncenter size-full wp-image-3559" src="http://andrewmorgan.ie/wp-content/uploads/2015/10/rdppassword.png" alt="rdppassword" width="655" height="84" /></a></p>
<p lang="en-GB" style="margin: 0in; font-family: Calibri; font-size: 11.0pt;">Optionally, you can include -ToClipboard to copy the text to the clipboard for easy copy -&gt; paste into an RDP file.</p>
<pre lang="en-GB" style="margin: 0in; font-family: Calibri; font-size: 11.0pt;">Get-RDPPassword -Password "SomethingSecure" -ToClipboard</pre>
<p lang="en-GB" style="margin: 0in; font-family: Calibri; font-size: 11.0pt;">And that&#8217;s it, simply import the module and off you go.</p>
<p lang="en-GB" style="margin: 0in; font-family: Calibri; font-size: 11.0pt;">If there is anything further you want to do with this, i.e. providing an RDP file to enter it into, accepting PSCredential as an argument or anything like that, get in contact and we&#8217;ll see what we can do!</p>
<h3 lang="en-GB" style="margin: 0in; font-family: Calibri; font-size: 11.0pt;"></h3>
<h3 lang="en-GB" style="margin: 0in; font-family: Calibri; font-size: 11.0pt;">Consent:</h3>
<p>&nbsp;</p>
<p lang="en-GB" style="margin: 0in; font-family: Calibri; font-size: 11.0pt;">This module is provided absolutely free of charge, using this module in a commercial product on the other hand is not condoned!</p>
<p lang="en-GB" style="margin: 0in; font-family: Calibri; font-size: 11.0pt;">Also, don&#8217;t ask me to reverse it, i&#8217;m not going to do it.</p>
<h3 lang="en-GB" style="margin: 0in; font-family: Calibri; font-size: 11.0pt;">Download:</h3>
<p>&nbsp;</p>
<p lang="en-GB" style="margin: 0in; font-family: Calibri; font-size: 11.0pt;"><a href="https://app.box.com/s/3007sq7aodyvirqgin3x08fupjw048es" target="_blank">Here:</a></p>
]]></content:encoded>
			<wfw:commentRss>http://andrewmorgan.ie/2015/10/new-module-creating-an-rdp-file-password-with-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dealing with multi numbered versions in powershell.</title>
		<link>http://andrewmorgan.ie/2015/09/dealing-with-multi-numbered-versions-in-powershell/</link>
		<comments>http://andrewmorgan.ie/2015/09/dealing-with-multi-numbered-versions-in-powershell/#comments</comments>
		<pubDate>Tue, 15 Sep 2015 14:37:27 +0000</pubDate>
		<dc:creator><![CDATA[andyjmorgan]]></dc:creator>
				<category><![CDATA[PowerShell Scripting]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Version Comparison]]></category>

		<guid isPermaLink="false">http://andrewmorgan.ie/?p=3523</guid>
		<description><![CDATA[So here&#8217;s a quick little blog about something i discovered in powershell while googling today. Lots of vendors like to use version numbers including Major.Minor.Build.Revision. An example of a vendor I was dealing with recently was Citrix themselves. The problem is, in powershell, it&#8217;s not that easy to take a string (text) representative of these, split it up then label it yourself. you&#8217;re splitting, taking objects in an array, assigning them values&#8230; nasty. Did you know .Net has a native [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><img class="size-thumbnail wp-image-403 alignright" src="http://andrewmorgan.ie/wp-content/uploads/2011/03/windows_powershell_icon-150x150.png" alt="Windows_PowerShell_icon" width="150" height="150" />So here&#8217;s a quick little blog about something i discovered in powershell while googling today.</p>
<p>Lots of vendors like to use version numbers including Major.Minor.Build.Revision.</p>
<p>An example of a vendor I was dealing with recently was Citrix themselves.</p>
<p><a href="http://andrewmorgan.ie/wp-content/uploads/2015/09/versionexample1.png"><img class="aligncenter size-full wp-image-3525" src="http://andrewmorgan.ie/wp-content/uploads/2015/09/versionexample1.png" alt="versionexample" width="841" height="264" /></a></p>
<p>The problem is, in powershell, it&#8217;s not that easy to take a string (text) representative of these, split it up then label it yourself. you&#8217;re splitting, taking objects in an array, assigning them values&#8230; nasty.</p>
<p><a href="http://andrewmorgan.ie/wp-content/uploads/2015/09/string.png"><img class="aligncenter size-full wp-image-3526" src="http://andrewmorgan.ie/wp-content/uploads/2015/09/string.png" alt="string" width="442" height="26" /></a></p>
<p>Did you know .Net has a native ability to do this?</p>
<p>Introducing <a href="https://msdn.microsoft.com/en-us/library/system.version(v=vs.110).aspx" target="_blank">system.version</a></p>
<p>Now with system.version, it&#8217;s very easy to do comparisons! Just cast your string into a [system.version] as below:</p>
<p><a href="http://andrewmorgan.ie/wp-content/uploads/2015/09/version.png"><img class="aligncenter size-full wp-image-3527" src="http://andrewmorgan.ie/wp-content/uploads/2015/09/version.png" alt="version" width="666" height="199" /></a></p>
<p>&nbsp;</p>
<p>After that, just compare the major, minor, build or revision at will!</p>
<p><a href="http://andrewmorgan.ie/wp-content/uploads/2015/09/example2.png"><img class="aligncenter size-full wp-image-3528" src="http://andrewmorgan.ie/wp-content/uploads/2015/09/example2.png" alt="example2" width="627" height="178" /></a></p>
<p>&nbsp;</p>
<p>Happy version comparing!</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewmorgan.ie/2015/09/dealing-with-multi-numbered-versions-in-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Accurately checking the Citrix PVS &#8220;cache in Ram, Overflow to disk&#8221; RAM cache size</title>
		<link>http://andrewmorgan.ie/2015/08/accurately-checking-the-citrix-pvs-cache-in-ram-overflow-to-disk-ram-cache-size/</link>
		<comments>http://andrewmorgan.ie/2015/08/accurately-checking-the-citrix-pvs-cache-in-ram-overflow-to-disk-ram-cache-size/#comments</comments>
		<pubDate>Fri, 07 Aug 2015 14:23:18 +0000</pubDate>
		<dc:creator><![CDATA[andyjmorgan]]></dc:creator>
				<category><![CDATA[Citrix]]></category>
		<category><![CDATA[PowerShell Scripting]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Provisioning Services]]></category>
		<category><![CDATA[RAM]]></category>

		<guid isPermaLink="false">http://andrewmorgan.ie/?p=3443</guid>
		<description><![CDATA[Citrix Provisioning services &#8220;Cache in RAM, overflow to disk&#8221;, even with it&#8217;s challenges is something I&#8217;ve always felt was a great idea, hell, I foresaw it&#8217;s implementation back in 2012! Not withstanding the issues that can occur when the cache is heavily in use, it&#8217;s a great piece of technology. One of the features you see on twitter repeatedly is trying to report on the exact size of the PVS cache in RAM. Many blogs and scripts (Matt&#8217;s here, as [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><img class="alignright  wp-image-3444" src="http://andrewmorgan.ie/wp-content/uploads/2015/08/Citrix_Provisioning_Services_Implementation.png" alt="Citrix_Provisioning_Services_Implementation" width="86" height="86" />Citrix Provisioning services &#8220;Cache in RAM, overflow to disk&#8221;, even with it&#8217;s challenges is something I&#8217;ve always felt was a great idea, hell, I foresaw it&#8217;s implementation <a href="http://andrewmorgan.ie/2012/10/on-e2e-geek-speak-iops-shared-storage-and-a-fresh-idea-part-1/" target="_blank">back in 2012</a>!</p>
<p>Not withstanding the issues that can occur when the cache is heavily in use, it&#8217;s a great piece of technology. One of the features you see on twitter repeatedly is trying to report on the exact size of the PVS cache in RAM.</p>
<p>Many blogs and scripts (Matt&#8217;s <a href="http://mattnics.com/?p=414" target="_blank">here</a>, as an example) will take the raw performance counter details for Non Paged Pool memory and assume this is the size of the cache. This is faulty logic, but close enough. It&#8217;s like looking into a can of beans and trying to determine which one gave you gas.</p>
<p>The Non paged Pool is a collective pool of memory used by the system that guarantee&#8217;s the services using it (drivers, etc) that the contents will never reach the disk and will always be maintained in memory. As an example, imagine you created your own disk driver, but the disk driver tried to reference it&#8217;s memory and it had since been flushed to the disk&#8230;. Chicken and Egg stuff!</p>
<p>Microsoft has a fairly clear description <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa965226(v=vs.85).aspx" target="_blank">here</a>:</p>
<pre style="text-align: center;">The memory manager creates the following memory pools that the system uses to allocate memory: nonpaged pool and paged pool. Both memory pools are located in the region of the address space that is reserved for the system and mapped into the virtual address space of each process. <strong>The nonpaged pool consists of virtual memory addresses that are guaranteed to reside in physical memory as long as the corresponding kernel objects are allocated.</strong></pre>
<p>So with this in mind, taking a total of the Non Paged Pool memory and assuming it&#8217;s PVS is &#8220;OK&#8221;&#8230; But not accurate. Many other sources can bloat that memory cache, particularly in x64 systems where limits on these pools are now enormous compared to the tiny pools we had to deal with in x86 architectures.</p>
<p>Nerdy digression aside, if you REALLY want accurate information on what&#8217;s going on inside of this pool. You need to grab a copy of Poolmon from the <a href="https://msdn.microsoft.com/library/windows/hardware/ff557573" target="_blank">Windows Driver Kit (WDK)</a>. Download the WDK, install it and you&#8217;ll find your poolmon in:</p>
<p>C:\Program Files (x86)\Windows Kits\10\Tools\x64\poolmon.exe</p>
<p>Once you have a copy, fire up poolmon and you&#8217;ll see in all their glory.</p>
<p><a href="http://andrewmorgan.ie/wp-content/uploads/2015/08/pvs.png"><img class="aligncenter size-full wp-image-3447" src="http://andrewmorgan.ie/wp-content/uploads/2015/08/pvs.png" alt="pvs" width="1118" height="508" /></a></p>
<p><em>Pro tip: Press &#8220;p&#8221; once to sort my non pooled, then &#8220;b&#8221; to sort by bytes used.</em></p>
<p>Each pool tag and the respective space they are using. Interestingly, the Citrix caching technology seems to use the &#8220;VhdR&#8221; pooltag allocation. There&#8217;s also a Microsoft Pool tag for this (http://blogs.technet.com/b/yongrhee/archive/2009/06/24/pool-tag-list.aspx) but the case sensitivity differences between VhdR and VHDr may make all the difference.</p>
<p>I did reach out to Citrix on this one, but they didn&#8217;t provide any further insight.</p>
<p>Any-who, if you want to see the size of your PVS cache accurately? Use PoolMon. Here&#8217;s a quick script using poolmon to get the GB value back:</p>
<pre class="p1"><span class="s1">$poolmonpath</span><span class="s2">=</span> <span class="s4">"d:\poolmon.exe"
</span><span class="s1">$poollog</span><span class="s2">=</span> <span class="s4">"$env:temp\poolmon.txt"
</span><span class="s5">if</span><span class="s3">(</span><span class="s4">test-path</span> <span class="s1">$poollog</span><span class="s3">){</span><span class="s4">Remove-Item</span> <span class="s1">$poollog</span><span class="s3">}
</span><span class="s6">Start-Process</span><span class="s4">-FilePath</span> <span class="s1">$poolmonpath</span> <span class="s4">-ArgumentList</span> <span class="s7">"-n $poollog"</span> <span class="s4">-Wait
</span><span class="s4">((</span><span class="s6">Get-Content</span> <span class="s1">$poollog</span> <span class="s2">|</span> <span class="s6">?</span><span class="s4"> {</span><span class="s1">$_</span> <span class="s2">-like</span> <span class="s7">"*VhdR*"</span><span class="s4">}) </span><span class="s2">-split</span> <span class="s7">"\s+"</span><span class="s4">)</span><span class="s2">[</span><span class="s8">6</span><span class="s2">]</span> <span class="s2">/</span><span class="s8">1gb
</span><span class="s5">if</span><span class="s3">(</span><span class="s4">test-path</span> <span class="s1">$poollog</span><span class="s3">){</span><span class="s4">Remove-Item</span> <span class="s1">$poollog</span><span class="s3">}</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://andrewmorgan.ie/2015/08/accurately-checking-the-citrix-pvs-cache-in-ram-overflow-to-disk-ram-cache-size/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Adding a list of Authorised files to RES Workspace Manager Building Block</title>
		<link>http://andrewmorgan.ie/2015/08/adding-a-list-of-authorised-files-to-res-workspace-manager-building-block/</link>
		<comments>http://andrewmorgan.ie/2015/08/adding-a-list-of-authorised-files-to-res-workspace-manager-building-block/#comments</comments>
		<pubDate>Tue, 04 Aug 2015 13:53:39 +0000</pubDate>
		<dc:creator><![CDATA[andyjmorgan]]></dc:creator>
				<category><![CDATA[PowerShell Scripting]]></category>
		<category><![CDATA[RES]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[RES Workspace Manager]]></category>

		<guid isPermaLink="false">http://andrewmorgan.ie/?p=3435</guid>
		<description><![CDATA[This is just a quick article on how to search for exe&#8217;s recursively in a specific path and add them to an RES Workspace Manager building block to be imported back in. I needed to do this recently as the customer in question had an application that lived on a network share and after 14+ years of development in this style, everyone was afraid to move it! Steps to use this script: Export an existing building block for the application [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><img class="alignright size-thumbnail wp-image-403" src="http://andrewmorgan.ie/wp-content/uploads/2011/03/windows_powershell_icon-150x150.png" alt="Windows_PowerShell_icon" width="150" height="150" />This is just a quick article on how to search for exe&#8217;s recursively in a specific path and add them to an RES Workspace Manager building block to be imported back in.</p>
<p>I needed to do this recently as the customer in question had an application that lived on a network share and after 14+ years of development in this style, everyone was afraid to move it!</p>
<p>Steps to use this script:</p>
<ul>
<li>Export an existing building block for the application you wish to authorize</li>
<li>Ensure the exported building block has at least one authorized file</li>
<li>Modify the $import and $exportbuildingblockpath</li>
<li>Modify the $exedirpath to be the path you wish to search recursively for exe&#8217;s.</li>
</ul>
<pre>$importBuildingBlockPath = 'H:\path\bb.xml'
$exportBuildingBlockPath = 'h:\path\export.xml'
 
$alreadyauth=@()
$ExeForAuth=@()
$exedirpath = "\\servername\Share\APPS"
 
 
Get-ChildItem -Recurse $dirpath | ?{!($_.psiscontainer) -and $_.Extension -like ".exe"}  | %{
    $ExeForAuth+=$_.fullname.ToLower()
}
 
 
[xml]$bb = Get-Content $importBuildingBlockPath
 
 
$bb.respowerfuse.buildingblock.application.appguard.authorizedfiles.authfile | %{
    $alreadyauth+=$_.authorizedfile.tolower()
}
 
 
Compare-Object $alreadyauth $ExeForAuth | ? {$_.SideIndicator -eq "=&gt;"} | % {
    $newnode=$bb.respowerfuse.buildingblock.application.appguard.authorizedfiles.authfile[0].Clone()
    $newnode.authorizedfile=$_.inputobject.tostring()                                                                                     
    $newnode.description="Auto Appended item via script"                                                                                        
    $newnode.process="*"                                                                                          
    $newnode.learningmode="no"                                                                                               
    $newnode.enabled="yes"   
    $bb.respowerfuse.buildingblock.application.appguard.authorizedfiles.AppendChild($newnode)
}
 
$bb.save($exportBuildingBlockPath)
</pre>
]]></content:encoded>
			<wfw:commentRss>http://andrewmorgan.ie/2015/08/adding-a-list-of-authorised-files-to-res-workspace-manager-building-block/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Viewing open files on a file server from powershell.</title>
		<link>http://andrewmorgan.ie/2012/12/viewing-open-files-on-a-file-server-from-powershell/</link>
		<comments>http://andrewmorgan.ie/2012/12/viewing-open-files-on-a-file-server-from-powershell/#comments</comments>
		<pubDate>Wed, 05 Dec 2012 14:55:23 +0000</pubDate>
		<dc:creator><![CDATA[andyjmorgan]]></dc:creator>
				<category><![CDATA[Clustering]]></category>
		<category><![CDATA[PowerShell Scripting]]></category>
		<category><![CDATA[Server Based Computing]]></category>
		<category><![CDATA[Virtual Desktop Infrastructure]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[XenApp]]></category>
		<category><![CDATA[XenDesktop]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SBC]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[VDI]]></category>
		<category><![CDATA[xenapp]]></category>

		<guid isPermaLink="false">http://andrewmorgan.ie/?p=2480</guid>
		<description><![CDATA[So this is a situation you should all be aware of in an SBC / VDI environment, despite all warnings, you&#8217;ve redirected folders to your network drive and your file servers are screaming in agony? Having been in this situation recently, I needed to audit and report on the types of files open on the file server, my hunch was a certain select number of users were running applications (like *gulp* lotus notes) from the network share. Disappointed with the [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><img class="alignright size-full" alt="/wp-content/uploads/2011/03/windows_powershell_icon.png?w=58&amp;h=58&amp;h=58" src="/wp-content/uploads/2011/03/windows_powershell_icon.png?w=58&amp;h=58&amp;h=58" height="58" width="58" />So this is a situation you should all be aware of in an SBC / VDI environment, despite all <a href="http://helgeklein.com/blog/2011/11/folder-redirection-denial-of-service-waiting-to-happen/" target="_blank">warnings</a>, you&#8217;ve redirected folders to your network drive and your file servers are screaming in agony?</p>
<p>Having been in this situation recently, I needed to audit and report on the types of files open on the file server, my hunch was a certain select number of users were running applications (like *gulp* lotus notes) from the network share.</p>
<p>Disappointed with the powershell scripts on the interwebs, I decided to write my own function to perform this task:</p>
<p>[sourcecode language=&#8221;powershell&#8221;]<br />
function get-openfiles{<br />
param(<br />
    $computername=@($env:computername),<br />
    $verbose=$false)<br />
    $collection = @()<br />
foreach ($computer in $computername){<br />
    $netfile = [ADSI]&quot;WinNT://$computer/LanmanServer&quot;</p>
<p>        $netfile.Invoke(&quot;Resources&quot;) | foreach {<br />
            try{<br />
                $collection += New-Object PsObject -Property @{<br />
        		  Id = $_.GetType().InvokeMember(&quot;Name&quot;, &#8216;GetProperty&#8217;, $null, $_, $null)<br />
        		  itemPath = $_.GetType().InvokeMember(&quot;Path&quot;, &#8216;GetProperty&#8217;, $null, $_, $null)<br />
        		  UserName = $_.GetType().InvokeMember(&quot;User&quot;, &#8216;GetProperty&#8217;, $null, $_, $null)<br />
        		  LockCount = $_.GetType().InvokeMember(&quot;LockCount&quot;, &#8216;GetProperty&#8217;, $null, $_, $null)<br />
        		  Server = $computer<br />
        		}<br />
            }<br />
            catch{<br />
                if ($verbose){write-warning $error[0]}<br />
            }<br />
        }<br />
    }<br />
    Return $collection<br />
}<br />
[/sourcecode]</p>
<p>The function above (get-openfiles) has been written to accept an array of servers to the command line and it will return the following items:</p>
<ul>
<li>The ID of the open file.</li>
</ul>
<ul>
<li>The server it&#8217;s open from.</li>
</ul>
<ul>
<li>The username who has the file open.</li>
</ul>
<ul>
<li>The amount of locks the file has.</li>
</ul>
<p><strong>A couple of quick examples for using this command are below:<br />
<code><br />
</code><br />
</strong> <span style="text-decoration:underline;">Retrieving open files from server1:</span><br />
<code><br />
</code><br />
<img class="aligncenter" alt="full" src="/wp-content/uploads/2012/12/full.png" height="261" width="595" /><br />
<code><br />
</code></p>
<p>[sourcecode language=&#8221;powershell&#8221;]get-openfiles -computername server1 | select server,itempath,lockcount[/sourcecode]</p>
<p><code><br />
</code><br />
<span style="text-decoration:underline;">Retrieve a count of open files that end with the nsf file type (<em>Lotus Notes</em>):</span><br />
<code><br />
</code><br />
<img class="aligncenter size-full wp-image-2483" alt="count" src="/wp-content/uploads/2012/12/count.png" height="37" width="595" /><br />
<code><br />
</code></p>
<p>[sourcecode language=&#8221;powershell&#8221;](get-open files -computername server1,server2 | ? {$_.itempath -like &quot;*.nsf*&quot;}).count()[/sourcecode]</p>
<p><code><br />
</code><br />
<span style="text-decoration:underline;">Retrieve a report of total open files on a number of file servers:</span><br />
<code><br />
</code><br />
<img class="aligncenter size-full wp-image-2487" alt="report" src="/wp-content/uploads/2012/12/report.png" height="64" width="595" /></p>
<p>&nbsp;</p>
<p>[sourcecode language=&#8221;powershell&#8221;]get-openfiles -computername server1,server2,server3,server4,server5 | group -property server[/sourcecode]</p>
<p><code> </code></p>
]]></content:encoded>
			<wfw:commentRss>http://andrewmorgan.ie/2012/12/viewing-open-files-on-a-file-server-from-powershell/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Monitoring Storage disk queue&#8217;s and IO with PowerShell</title>
		<link>http://andrewmorgan.ie/2012/11/monitoring-storage-disk-queues-and-io-with-powershell/</link>
		<comments>http://andrewmorgan.ie/2012/11/monitoring-storage-disk-queues-and-io-with-powershell/#comments</comments>
		<pubDate>Fri, 30 Nov 2012 09:38:45 +0000</pubDate>
		<dc:creator><![CDATA[andyjmorgan]]></dc:creator>
				<category><![CDATA[Citrix]]></category>
		<category><![CDATA[PowerShell Scripting]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[XenApp]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[xenapp]]></category>

		<guid isPermaLink="false">http://andrewmorgan.ie/?p=2469</guid>
		<description><![CDATA[Here&#8217;s one that used to bother me alot. The problem usually went as follows: &#8220;Your XenApp servers have very high disk queue&#8217;s and IO&#8221; &#8220;What&#8217;s causing it?&#8221; &#8220;dunno&#8230;&#8221; With Server 2008, the task manager&#8217;s resource monitor feature will help you find these items. But in server 2003 this was a perilous task. The specific details for disk io per process are stored in performance monitor under each specific process running. Trying to analyse each process was a massive pain, but [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><img class="alignright size-full" alt="/wp-content/uploads/2011/03/windows_powershell_icon.png?w=58&amp;h=58&amp;h=58" src="/wp-content/uploads/2011/03/windows_powershell_icon.png?w=58&amp;h=58&amp;h=58" height="58" width="58" />Here&#8217;s one that used to bother me alot. The problem usually went as follows:</p>
<p>&#8220;Your XenApp servers have very high disk queue&#8217;s and IO&#8221;</p>
<p>&#8220;What&#8217;s causing it?&#8221;</p>
<p>&#8220;dunno&#8230;&#8221;</p>
<p>With Server 2008, the task manager&#8217;s resource monitor feature will help you find these items. But in server 2003 this was a perilous task. The specific details for disk io per process are stored in performance monitor under each specific process running. Trying to analyse each process was a massive pain, but powershell can do some very clever work to help alleviate this!</p>
<p>I wrote two quick functions which act similar to &#8220;top&#8221; in linux for giving an on screen view, updating at interval of what exactly is creating IO activity. These two functions are:</p>
<p>get-IODataBytes:</p>
<p><img class="aligncenter size-full wp-image-2470" alt="storageio" src="/wp-content/uploads/2012/11/storageio.png" height="233" width="595" /></p>
<p>Get-IODataOperations</p>
<p><img class="aligncenter size-full wp-image-2471" alt="storageioops" src="/wp-content/uploads/2012/11/storageioops.png" height="240" width="595" /></p>
<p>The code for these functions are below:</p>
<p>[sourcecode language=&#8221;powershell&#8221;]<br />
function get-iodatabytes{<br />
    $result=(get-counter -counter &quot;Process(*)IO Data Bytes/sec&quot; -ea 0).countersamples | ? {$_.cookedvalue -gt 0} | select instancename,@{Name=&quot;SessionID&quot;;Expression={if ($_.path.contains(&quot;#&quot;)){($_.path.split(&quot;#)&quot;))[1]}else{&quot;0&quot;}}},@{Name=&quot;IO Data Bytes/sec&quot;;Expression={[math]::Round($_.cookedvalue,0)}},@{Name=&quot;IO Data KBytes/sec&quot;;Expression={[math]::Round($_.cookedvalue / 1024,0)}} | sort -Descending &quot;IO Data Bytes/sec&quot; | ft<br />
    $currentqueue=(((get-counter -counter &quot;PhysicalDisk(0 C:)Current Disk Queue Length&quot; -ea 0).countersamples) | select cookedvalue).cookedvalue<br />
    clear<br />
    write-warning &quot;Hit [CTRL] + [C] to exit live capture&quot;<br />
    write-host &quot;Current Disk queue: $currentqueue&quot;<br />
    return $Result<br />
}</p>
<p>FUnction get-IODataOperations {<br />
    $result=(get-counter -counter &quot;Process(*)IO Data Operations/sec&quot; -ea 0).countersamples | ? {$_.cookedvalue -gt 0} | select instancename,@{Name=&quot;SessionID&quot;;Expression={if ($_.path.contains(&quot;#&quot;)){($_.path.split(&quot;#)&quot;))[1]}else{&quot;0&quot;}}},@{Name=&quot;IO Data Operations/sec&quot;;Expression={[math]::Round($_.cookedvalue,0)}} | sort -Descending &quot;IO Data Operations/sec&quot; | ft<br />
    $currentqueue=(((get-counter -counter &quot;PhysicalDisk(0 C:)Current Disk Queue Length&quot; -ea 0).countersamples) | select cookedvalue).cookedvalue<br />
    clear<br />
    write-warning &quot;Hit [CTRL] + [C] to exit live capture&quot;<br />
    write-host &quot;Current Disk queue: $currentqueue&quot;<br />
    return $Result<br />
}</p>
<p>[/sourcecode]</p>
<p>if you wish to loop one of these functions, simply use the following code:</p>
<p>[sourcecode language=&#8221;powershell&#8221;]<br />
while ($true){<br />
get-iodataoperations<br />
start-sleep 1<br />
}<br />
[/sourcecode]</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewmorgan.ie/2012/11/monitoring-storage-disk-queues-and-io-with-powershell/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Silently installing the Citrix Edgesight ActiveX plugin</title>
		<link>http://andrewmorgan.ie/2012/09/silently-installing-the-citrix-edgesight-activex-plugin/</link>
		<comments>http://andrewmorgan.ie/2012/09/silently-installing-the-citrix-edgesight-activex-plugin/#comments</comments>
		<pubDate>Wed, 05 Sep 2012 11:30:49 +0000</pubDate>
		<dc:creator><![CDATA[andyjmorgan]]></dc:creator>
				<category><![CDATA[Batch Scripting]]></category>
		<category><![CDATA[Citrix]]></category>
		<category><![CDATA[Edgesight]]></category>
		<category><![CDATA[PowerShell Scripting]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[cmd]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://andrewmorgan.ie/?p=2214</guid>
		<description><![CDATA[Just a really quick blog post on how to silently install the reporting agent inside your environment. Log into a server / client without the EdgeSight plugin installed, and browse to the edgesight website. Once logged in, you will receive the usual prompt to install the software: Install the software and ensure it works, then fire up a command prompt and browse down to &#8220;c:windowsdownloaded program files&#8221;. Once in this folder, a DIR will reveal the ActiveX plugin &#8220;csmdbprov.dll&#8221;. Now [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><img class="alignright" style="width:67px;height:73px;" src="/wp-content/uploads/2011/11/es-logo.jpg?w=112&amp;h=112&amp;h=112" alt="" width="112" height="112" />Just a really quick blog post on how to silently install the reporting agent inside your environment.</p>
<p>Log into a server / client without the EdgeSight plugin installed, and browse to the edgesight website. Once logged in, you will receive the usual prompt to install the software:</p>
<p><img class="aligncenter size-full wp-image-2216" title="1" src="/wp-content/uploads/2012/08/1.png" alt="" width="464" height="212" /></p>
<p>Install the software and ensure it works, then fire up a command prompt and browse down to &#8220;c:windowsdownloaded program files&#8221;. Once in this folder, a DIR will reveal the ActiveX plugin &#8220;csmdbprov.dll&#8221;.</p>
<p><img class="aligncenter size-full wp-image-2217" title="2" src="/wp-content/uploads/2012/08/2.png" alt="" width="536" height="228" /></p>
<p>Now simply copy this file out to shared storage:</p>
<p><img class="aligncenter" title="3" src="/wp-content/uploads/2012/08/31.png" alt="" width="521" height="45" /></p>
<p>Once done, now its scripting time!</p>
<p>Below are two examples in batch (.bat , .cmd) or PowerShell (.ps1) for achieving this:</p>
<p>(please amend h:csmdbprov.dll to the path you use)</p>
<p><strong>Batch:</strong></p>
<p>[sourcecode language=&#8221;text&#8221;]<br />
copy h:csmdbprov.dll &quot;c:windowsdownloaded program files&quot;<br />
regsvr32 /s &quot;c:windowsdownloaded program files&quot;<br />
[/sourcecode]</p>
<p><strong>Powershell:</strong></p>
<p>[sourcecode language=&#8221;powershell&#8221;]<br />
if (test-path h:csmdbprov.dll){<br />
	copy-item H:csmdbprov.dll &#8216;C:WindowsDownloaded Program Files&#8217; -Force<br />
	start-process regsvr32 -ArgumentList &quot;/s &quot;&quot;C:WindowsDownloaded Program Filescsmdbprov.dll&quot;&quot;&quot; -wait<br />
}<br />
[/sourcecode]</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewmorgan.ie/2012/09/silently-installing-the-citrix-edgesight-activex-plugin/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Disable the Windows Firewall in Server 8 Beta, with Powershell</title>
		<link>http://andrewmorgan.ie/2012/03/disable-the-windows-firewall-in-server-8-beta-with-powershell/</link>
		<comments>http://andrewmorgan.ie/2012/03/disable-the-windows-firewall-in-server-8-beta-with-powershell/#comments</comments>
		<pubDate>Sat, 17 Mar 2012 14:08:57 +0000</pubDate>
		<dc:creator><![CDATA[andyjmorgan]]></dc:creator>
				<category><![CDATA[PowerShell Scripting]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[Firewall]]></category>
		<category><![CDATA[NetSecurity]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Windows Server 8 Beta]]></category>

		<guid isPermaLink="false">http://andrewmorgan.ie/?p=1729</guid>
		<description><![CDATA[(Note: this will also work with Windows 8 Consumer Preview) While troubleshooting an issue in windows server 8&#8217;s new Powershell Web Access, I had the need to disable the windows firewall. Normally I would use a &#8220;netsh firewall&#8221; command, but when running this in windows server 8 we receive the notification: &#8220;In future versions of Windows, Microsoft might remove the Netsh Functionality for windows firewall with Advanced Security&#8221; &#8220;If you currently use Netsh firewall to configure and manage Windows Firewall [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><a href="/wp-content/uploads/2012/03/beta.jpg"><img class="alignright size-full wp-image-1730" title="Beta" src="/wp-content/uploads/2012/03/beta-e1331990113658.jpg" alt="" width="74" height="62" /></a></p>
<p>(<strong>Note:</strong> this will also work with Windows 8 Consumer Preview)</p>
<p>While troubleshooting an issue in windows server 8&#8217;s new Powershell Web Access, I had the need to disable the windows firewall. Normally I would use a &#8220;netsh firewall&#8221; command, but when running this in windows server 8 we receive the notification:</p>
<p><em>&#8220;In future versions of Windows, Microsoft might remove the Netsh Functionality for windows firewall with Advanced Security&#8221;</em></p>
<p><em>&#8220;If you currently use Netsh firewall to configure and manage Windows Firewall with advanced Security, Microsoft recommends that you transition to Windows Powershell.&#8221;</em></p>
<p>This message continues in the screenshot below:<br />
<code><br />
</code><br />
<a href="/wp-content/uploads/2012/03/warning.png"><img class="wp-image-1731 aligncenter" title="warning" src="/wp-content/uploads/2012/03/warning.png" alt="" width="600" height="147" /></a><br />
<code><br />
</code><br />
So with the warning in mind, I decided it was time to learn the new thing for the day and off I went to find out how to quickly disable the firewall using powershell!</p>
<p>As above the first clue is in the message, a new module seems to be available on both Windows 8 and Server 8. So with a quick <strong>get-module -listavailable</strong> I can see netsecurity listed:<br />
<code><br />
</code><br />
<a href="/wp-content/uploads/2012/03/net-security.png"><img class="aligncenter size-full wp-image-1732" title="net security" src="/wp-content/uploads/2012/03/net-security.png" alt="" width="600" height="305" /></a><br />
<code><br />
</code><br />
&#8220;So what commands can I use with the netsecurity module&#8221; I asked myself. I ran a quick &#8220;<strong>Get-Command -module NetSecurity</strong>&#8221; and was overwhelmed with a large list of potential candidates as below:<br />
<code><br />
</code><br />
<a href="/wp-content/uploads/2012/03/firewall-profile.png"><img class="aligncenter  wp-image-1733" title="firewall profile" src="/wp-content/uploads/2012/03/firewall-profile.png" alt="" width="600" height="281" /></a><br />
<code><br />
</code><br />
So I used the trusted &#8220;Import-Module NetSecurity&#8221; command and set about reading the help files. Or so I thought&#8230;<br />
<code><br />
</code><br />
<a href="/wp-content/uploads/2012/03/help.png"><img class="aligncenter size-full wp-image-1734" title="help" src="/wp-content/uploads/2012/03/help.png" alt="" width="600" height="44" /></a><br />
<code><br />
</code><br />
As with PowerShell 3.0, the helpfiles for Powershell are not completely installed by default, we need to run update-help to download the powershell help files. This is causing quite a debate in the powershell community, so I&#8217;m not going to get into this, personally I think its a good idea.</p>
<p>Anyway, so off I went to update the help, <em>or so I thought</em>:<br />
<code><br />
</code><br />
<a href="/wp-content/uploads/2012/03/error1.png"><img class="aligncenter size-full wp-image-1735" title="error1" src="/wp-content/uploads/2012/03/error1.png" alt="" width="600" height="105" /></a><br />
<code><br />
</code><br />
<em>Bugger&#8230;</em></p>
<p>I&#8217;ll admit, this list had me scratching my head for some time, but I soon enough stumbled across the important command on this list for my objective. &#8220;<strong>Get-NetFirewallProfile&#8221;</strong>.</p>
<p>Get-NetFirewallProfile lists out the firewall profiles for your machine. The profiles are separated out into Domain, Public and Private as you can see in the screen-shot below:<br />
<code><br />
</code><br />
<a href="/wp-content/uploads/2012/03/crossreference.png"><img class="aligncenter size-full wp-image-1736" title="crossreference" src="/wp-content/uploads/2012/03/crossreference.png" alt="" width="600" height="364" /></a><br />
<code><br />
</code><br />
Now that we&#8217;re aware of where the profiles live, its just a simple task of piping the current profiles, into a &#8220;<strong>Set-NetFirewallProfile</strong>&#8221; command to turn the profiles off.</p>
<p>Below is a quick on-liner to disable the windows firewall in Server 8 or Windows 8 completely:<br />
<code><br />
</code></p>
<p>[sourcecode language=&#8221;powershell&#8221;]<br />
Import-Module NetSecurity -ea Stop ; Get-NetFirewallProfile | Set-NetfirewallProfile -Enabled False<br />
[/sourcecode]</p>
<p><code><br />
</code><br />
And that&#8217;s it!<br />
<code><br />
</code><br />
<a href="/wp-content/uploads/2012/03/result.png"><img class="aligncenter size-full wp-image-1741" title="result" src="/wp-content/uploads/2012/03/result.png" alt="" width="600" height="313" /></a><br />
<code><br />
</code><br />
And once finished troubleshooting, you can turn it back on as below:<br />
<code><br />
</code></p>
<p>[sourcecode language=&#8221;powershell&#8221;]<br />
Import-Module NetSecurity -ea Stop ; Get-NetFirewallProfile | Set-NetfirewallProfile -Enabled True<br />
[/sourcecode]</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewmorgan.ie/2012/03/disable-the-windows-firewall-in-server-8-beta-with-powershell/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Friday Fun: Powershell with Citrix PNAgent.</title>
		<link>http://andrewmorgan.ie/2012/02/friday-fun-powershell-with-citrix-pnagent/</link>
		<comments>http://andrewmorgan.ie/2012/02/friday-fun-powershell-with-citrix-pnagent/#comments</comments>
		<pubDate>Fri, 24 Feb 2012 10:39:50 +0000</pubDate>
		<dc:creator><![CDATA[andyjmorgan]]></dc:creator>
				<category><![CDATA[Citrix]]></category>
		<category><![CDATA[PowerShell Scripting]]></category>
		<category><![CDATA[XenApp]]></category>
		<category><![CDATA[XenDesktop]]></category>
		<category><![CDATA[PNagent]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://andrewmorgan.ie/?p=1675</guid>
		<description><![CDATA[This is something I was playing with for a while. I couldn&#8217;t quite get the conversions right without over complicating the script. But as with everything I do, Remko Weijnen, the legend that he is read my mind from afar and published the following fantastic article: Scripting Citrix Online Plugin Settings which basically made my script look like it was written by a two year old! So with his much improved code I set about writing a script to query the Program Neighbourhood Agent&#8217;s [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><a href="/wp-content/uploads/2011/03/windows_powershell_icon.png"><img class="alignright  wp-image-403" title="Windows_PowerShell_icon" src="/wp-content/uploads/2011/03/windows_powershell_icon.png?w=150" alt="" width="58" height="66" /></a>This is something I was playing with for a while. I couldn&#8217;t quite get the conversions right without over complicating the script. But as with everything I do, <a title="An amazing blog, i regularly read from Remko." href="http://www.remkoweijnen.nl/blog/">Remko Weijnen</a>, the legend that he is read my mind from afar and published the following fantastic article: <a href="http://www.remkoweijnen.nl/blog/2012/02/13/scripting-citrix-online-plugin-settings/#more-2404" target="_blank">Scripting Citrix Online Plugin Settings</a> which basically made my script look like it was written by a two year old!</p>
<p>So with his much improved code I set about writing a script to query the Program Neighbourhood Agent&#8217;s applications and launching them too with powershell.</p>
<p>By default, when Program Neighbourhood Agent launches, it populates the Application Model key(s) in HKEY_CURRENT_USERSoftwareCitrixPNAgent.</p>
<p><a href="/wp-content/uploads/2012/02/reg-keys.png"><img class="aligncenter size-full wp-image-1697" title="reg keys" src="/wp-content/uploads/2012/02/reg-keys.png" alt="" width="600" height="245" /></a></p>
<p>After the launch, we can use powershell to convert these binary keys into useable data, stick them all together then pull the application details.</p>
<p>With the below script, you can:</p>
<p><strong>Query applications published:</strong><code><br />
</code></p>
<p><a href="/wp-content/uploads/2012/02/get-pnapplication.png" target="_blank"><img class="size-full wp-image-1683 aligncenter" title="get-pnapplication" src="/wp-content/uploads/2012/02/get-pnapplication.png" alt="" width="600" height="104" /></a> <code></code><br />
<strong>Filter query published applications:</strong></p>
<p><a href="/wp-content/uploads/2012/02/filter-apps.png" target="_blank"><img class="aligncenter size-full wp-image-1684" title="filter apps" src="/wp-content/uploads/2012/02/filter-apps.png" alt="" width="600" height="42" /></a><code><br />
</code><br />
<strong>Launch Published applications:</strong></p>
<p><a href="/wp-content/uploads/2012/02/start-app.png" target="_blank"><img class="aligncenter size-full wp-image-1685" title="start-app" src="/wp-content/uploads/2012/02/start-app.png" alt="" width="600" height="23" /></a><code><br />
</code><br />
<strong>And if you&#8217;re crazy, auto launch all applications:</strong><br />
<code><br />
<a href="/wp-content/uploads/2012/02/launch-all.png"><img class="aligncenter size-full wp-image-1686" title="launch all" src="/wp-content/uploads/2012/02/launch-all.png" alt="" width="600" height="22" /></a></code></p>
<p>&nbsp;</p>
<p>The script can be found after the jump below:</p>
<p><span id="more-1675"></span></p>
<p>[sourcecode language=&#8221;powershell&#8221;]<br />
function get-pnapplication {<br />
    param(<br />
        [switch]$showdisabled)</p>
<p>    $bytesin=@()<br />
    $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey(&quot;CurrentUser&quot;, [String]::Empty)<br />
    # Read our Key (with write access)<br />
    $key = $Reg.OpenSubKey(&quot;SoftwareCitrixPNAgent&quot;, $true)</p>
<p>    # Read value as Byte Array<br />
    $key.GetValueNames() | where {$_ -like &quot;application model*&quot;} | %{<br />
        $bytesIn += $Key.GetValue(&quot;$_&quot;)}</p>
<p>    # Copy the Bytes to a String<br />
    $encode = New-Object System.Text.ASCIIEncoding<br />
    $rawData = $Encode.GetString($bytesIn)</p>
<p>    # Replace spaces in element names with underscores<br />
    $data = $rawData | Foreach-Object {<br />
        [regex]::replace($_,‘&lt;([^&gt;]+)&gt;’,{$args[0] -replace ‘  ‘,‘ ’})<br />
    }</p>
<p>    # Add dummy Root element<br />
    $data = &quot;&lt;root&gt;$data&lt;/root&gt;&quot;</p>
<p>    # Load the data into XML Object<br />
    $xml = New-Object Xml.XmlDocument<br />
    $xml.LoadXml($data)</p>
<p>    foreach ($app in $xml.root.appdata){</p>
<p>        if ($app.details.settings.appisdesktop -eq &quot;true&quot;){$type=&quot;Desktop&quot;}<br />
        Else{$type=&quot;Application&quot;}<br />
        if ($showdisabled -ne $true){<br />
            if ($app.details.settings.appisdisabled -eq $true){continue}<br />
        }<br />
         $item=new-object PSObject -Property @{<br />
            Name=$app.FName;<br />
            InName=$app.inname;<br />
            Description=$app.details.settings.Description<br />
            Type=$type<br />
        }#end report<br />
        $report+=@($item)<br />
    }#end for</p>
<p>        return $report<br />
}#end function</p>
<p>function start-pnapplication{<br />
    param(<br />
        [Parameter(<br />
    		Position=0,<br />
    		Mandatory=$true,<br />
    		ValueFromPipeline=$true,<br />
    		ValueFromPipelineByPropertyName=$true)]<br />
        [string]$InName,<br />
        [string]$PnAgentPath=&quot;C:Program Files (x86)CitrixICA Clientpnagent.exe&quot;)</p>
<p>    if (!(test-path $Pnagentpath)){write-warning &quot;cannot find Pnagent, breaking&quot;}</p>
<p>    start-process $pnagentpath -ArgumentList &quot;/qlaunch &quot;&quot;$inname&quot;&quot;&quot;<br />
}</p>
<p>[/sourcecode]</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewmorgan.ie/2012/02/friday-fun-powershell-with-citrix-pnagent/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Removing users access to &#8220;Devices and Printers&#8221; in a Server 2008 R2 / Win 7 Environment.</title>
		<link>http://andrewmorgan.ie/2012/01/removing-users-access-to-devices-and-printers-in-a-server-2008-r2-win-7-environment/</link>
		<comments>http://andrewmorgan.ie/2012/01/removing-users-access-to-devices-and-printers-in-a-server-2008-r2-win-7-environment/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 11:49:58 +0000</pubDate>
		<dc:creator><![CDATA[andyjmorgan]]></dc:creator>
				<category><![CDATA[PowerShell Scripting]]></category>
		<category><![CDATA[Workspace Manager]]></category>
		<category><![CDATA[XenApp]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[RES Software]]></category>
		<category><![CDATA[RES WorkspaceManager]]></category>

		<guid isPermaLink="false">http://andrewmorgan.ie/?p=1312</guid>
		<description><![CDATA[I love a good challenge. Recently I read the following article from Microsoft about how to tackle the title of this blog. This hack didn&#8217;t actually stop the users from accessing the cpl as clever users will just use rundll32 to get around the limitation. This also knocked other &#8220;show the following control panel items&#8221; policies out. This really inst a huge issue to most environments, as users will probably want to enumerate their printers at one stage or another. But in a RES [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><img class="alignright" src="/wp-content/uploads/2012/01/winlogo.png?w=75&amp;h=75" alt="" width="75" height="75" />I love a good challenge. Recently I read the<a href="http://support.microsoft.com/kb/2018577" target="_blank"> following article</a> from Microsoft about how to tackle the title of this blog. This hack didn&#8217;t actually stop the users from accessing the cpl as clever users will just use rundll32 to get around the limitation. This also knocked other &#8220;show the following control panel items&#8221; policies out.</p>
<p>This really inst a huge issue to most environments, as users will probably want to enumerate their printers at one stage or another. But in a RES Workspace manager environment, RES provide a much better interface for printer management which really defunct&#8217;s and eliminates the need for the windows method.</p>
<p>The culprit can be seen below:</p>
<p><a href="/wp-content/uploads/2012/01/culprit.png"><img class="aligncenter size-full wp-image-1325" title="culprit" src="/wp-content/uploads/2012/01/culprit.png" alt="" width="411" height="149" /></a></p>
<p>This problem for me, all stems from the &#8220;<a href="http://technet.microsoft.com/en-us/library/cc938271.aspx" target="_blank">NoSetFolders</a>&#8221; chestnut, anyone who&#8217;s tried to lock down a Terminal services environment from Windows Server 2000 onwards will be aware that this <em>&#8220;handy&#8221;</em> group policy removes the users ability to use [Windows Key] and [E] to open explorer. This issue still isn&#8217;t fixed in 2008 R2 and I&#8217;m beginning to think Microsoft just wont fix it. Hey no big deal right? Yes, quite a big deal if you ask pedantic users.</p>
<p><em>Anyway</em>, I digress. Once you remove the NoSetFolders key, the user has the ability to see the devices and printers as below on the start menu, hence my situation.</p>
<p>To remove this folder view for all users, its time to hack the registry!</p>
<p>The Class ID belonging to this start menu item can be found here:</p>
<pre>HKEY_CLASSES_ROOTCLSID{A8A91A66-3A7D-4424-8D24-04E180695C7A}</pre>
<p>This dastardly key also has a 32bit relation that can be found here:</p>
<pre>HKEY_CLASSES_ROOTWow6432NodeCLSID{A8A91A66-3A7D-4424-8D24-04E180695C7A}</pre>
<p>As with my previous post about removing <a href="http://andrewmorgan.ie/2012/01/16/removing-screen-resolution-and-personalize-shell-extensions-from-a-users-desktop-session/" target="_blank">screen resolution and personalise</a>, its just a matter of removing the users ability to see this registry key.</p>
<p>So below you will find the steps to take to remove this item:</p>
<ol>
<li>Take a backup of this key, you’ll thank me if you get it wrong!</li>
<li>Browse down to HKEY_CLASSES_ROOTCLSID{A8A91A66-3A7D-4424-8D24-04E180695C7A}</li>
<li>right click this key, choose permissions, click advanced then owner</li>
<li>Select administrators from the list, then choose “Apply”.</li>
<li>browse to the permissions tab and remove the “users” group. (you may need to remove inheritance)</li>
<li>Click “apply”, then “ok”.</li>
<li>Repeat step 2 to 6 on HKEY_CLASSES_ROOTWow6432NodeCLSID{A8A91A66-3A7D-4424-8D24-04E180695C7A}</li>
<li>Tada! go grab a coffee to celebrate your domination over the windows operating system.</li>
</ol>
<p>And that&#8217;s it, even if the user tries to view the option theres a blank place on the start menu where devices and printers should be. Check back next week and I&#8217;ll show you how to replace this shell icon with PowerPrint from RES software.</p>
<p>PS: You can also quite easily script this, <a href="http://www.remkoweijnen.nl/blog/" target="_blank">Remko</a> provided me with a great script that I&#8217;ve modified below to suit this purpose.</p>
<p><span id="more-1312"></span></p>
<p>[sourcecode language=&#8221;Powershell&#8221;]</p>
<p>## #############################################################################<br />
## 	Restrict certain Explorer items via registry key.<br />
## #############################################################################<br />
if (!(get-psdrive hkcr -ea 0)){New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT | out-null}</p>
<p> function get-elevatedprivileges{<br />
$definition = @&quot;<br />
    using System;<br />
    using System.Runtime.InteropServices;</p>
<p>    namespace Win32Api<br />
    {</p>
<p>       public class NtDll<br />
       {<br />
          [DllImport(&quot;ntdll.dll&quot;, EntryPoint=&quot;RtlAdjustPrivilege&quot;)]<br />
          public static extern int RtlAdjustPrivilege(ulong Privilege, bool Enable, bool CurrentThread, ref bool Enabled);<br />
       }<br />
    }<br />
&quot;@<br />
    Add-Type -TypeDefinition $definition -PassThru | out-null</p>
<p>    $bEnabled = $false</p>
<p>    # Enable SeTakeOwnershipPrivilege<br />
    $res = [Win32Api.NtDll]::RtlAdjustPrivilege(9, $true, $false, [ref]$bEnabled)<br />
}</p>
<p>function take-ownership{<br />
    param(<br />
        [Parameter(Mandatory = $true,Position = 0,valueFromPipeline=$true)]<br />
        [string]$regkey)<br />
    $key = [Microsoft.Win32.Registry]::ClassesRoot.OpenSubKey($regkey, [Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree,[System.Security.AccessControl.RegistryRights]::takeownership)<br />
    $acl = $key.GetAccessControl()<br />
    $acl.SetOwner([System.Security.Principal.NTAccount]&quot;Administrators&quot;)</p>
<p>    #taking ownership first<br />
    $key.SetAccessControl($acl)</p>
<p>    #my bit &#8211; give admin full access<br />
    $rule = New-Object System.Security.AccessControl.RegistryAccessRule(&quot;Administrators&quot;,&quot;FullControl&quot;,&quot;allow&quot;)<br />
    $acl.addaccessrule($rule)<br />
    $key.SetAccessControl($acl)<br />
    #end bit</p>
<p>}#end ownership function.</p>
<p>function remove-useracl{<br />
     param(<br />
        [Parameter(Mandatory = $true,Position = 0,valueFromPipeline=$true)]<br />
        [string]$regkey)<br />
    write-host &quot;$regkey&quot;<br />
    #remove inheritance<br />
    $acl = Get-Acl $regkey<br />
    $acl.SetAccessRuleProtection($true, $true)<br />
    set-acl $regkey -aclobject $acl</p>
<p>    #Remove users<br />
    $acl = Get-Acl $regkey<br />
    foreach ($rule in $acl.access){if ($rule.identityreference -eq &quot;BUILTINUsers&quot;){$acl.RemoveAccessRuleSpecific($rule)}}<br />
    set-acl $regkey -AclObject $acl<br />
}#end acl function.</p>
<p>#define keys to be restricted<br />
$keys=@(&quot;CLSID{A8A91A66-3A7D-4424-8D24-04E180695C7A}&quot;, # printers and devices<br />
&quot;Wow6432NodeCLSID{A8A91A66-3A7D-4424-8D24-04E180695C7A}&quot; # 32bit Printers and devices<br />
)</p>
<p>#elevate priviledges</p>
<p>get-elevatedprivileges</p>
<p>#restrict each key<br />
foreach ($key in $keys){<br />
    if (test-path &quot;hkcr:$key&quot;){<br />
        take-ownership -regkey $key<br />
        remove-useracl -regkey &quot;hkcr:$key&quot;<br />
    }<br />
}<br />
[/sourcecode]</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewmorgan.ie/2012/01/removing-users-access-to-devices-and-printers-in-a-server-2008-r2-win-7-environment/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
