<?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; PNagent</title>
	<atom:link href="http://andrewmorgan.ie/tag/pnagent/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>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>
	</channel>
</rss>
