<?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>PeetersOnline &#187; Config</title>
	<atom:link href="http://www.peetersonline.nl/index.php/tag/config/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.peetersonline.nl</link>
	<description>Using Powershell for (virtually) everything!</description>
	<lastBuildDate>Fri, 19 Aug 2011 09:22:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Increment PowerGUI Xml Version with Powershell</title>
		<link>http://www.peetersonline.nl/index.php/powershell/increment-powergui-xml-version-with-powershell/</link>
		<comments>http://www.peetersonline.nl/index.php/powershell/increment-powergui-xml-version-with-powershell/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 12:14:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerGUI]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Config]]></category>
		<category><![CDATA[Xml]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/?p=387</guid>
		<description><![CDATA[If you are using PowerGUI (which you should) and some of your collaegues do too, you might want to use a central configuration. Whenever you want to update the central configuration xml file, you need to increment the version number in order to push this change out to your collaegues. The following function increments the <a href='http://www.peetersonline.nl/index.php/powershell/increment-powergui-xml-version-with-powershell/'>[...]</a>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>If you are using <a href="http://powergui.org">PowerGUI</a> (which you should) and some of your collaegues do too, you might want to use a <a href="http://wiki.powergui.org/index.php/Customizing_PowerGUI_Configuration">central configuration</a>. Whenever you want to update the central configuration xml file, you need to increment the version number in order to push this change out to your collaegues. The following function increments the version number for you and even allows you to store the new file to the central location at the same time. All without having to edit the complex xml file manually. It even saves a backup copy of your central config file in case you mess up ;) It assumes you use a simple x.y version number, so please start out with 2.0 when setting up your config.<br />
To update your central config: just make the modifications within <a href="http://powergui.org" target='_blank'>PowerGUI</a> and then run this function.</p>
<p><span id="more-387"></span></p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #0000FF;">Function</span> Increment<span style="color: pink;">-</span>PowerGuiXmlVersion
	<span style="color: #000000;">&#123;</span>
	<span style="color: #0000FF;">Param</span><span style="color: #000000;">&#40;</span>
	<span style="color: #800080;">$PersonalXmlFile</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Join-Path</span> <span style="color: #800080;">$env</span>:appdata <span style="color: #800000;">&quot;Quest Software\PowerGUI\config.xml&quot;</span><span style="color: #000000;">&#41;</span><span style="color: pink;">,</span>
	<span style="color: #800080;">$CentralXmlFile</span> <span style="color: pink;">=</span> <span style="color: #800000;">'P:\Centrally Managed Files\config.xml'</span><span style="color: pink;">,</span>
	<span style="color: #800080;">$XPath</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;//container[@name='version']&quot;</span><span style="color: pink;">,</span>
	<span style="color: #800080;">$IncrementMajor</span> <span style="color: pink;">=</span> <span style="color: #800080;">$false</span><span style="color: pink;">,</span>
	<span style="color: #800080;">$IncrementMinor</span> <span style="color: pink;">=</span> <span style="color: #800080;">$true</span>
	<span style="color: #000000;">&#41;</span>
&nbsp;
	<span style="color: #008000;"># Load central xml file (for backup and reading the current version number)</span>
	<span style="color: #800080;">$CentralConfig</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Xml.XmlDocument
	<span style="color: #800080;">$CentralConfig</span>.Load<span style="color: #000000;">&#40;</span><span style="color: #800080;">$CentralXmlFile</span><span style="color: #000000;">&#41;</span>
&nbsp;
	<span style="color: #008000;"># Select the correct node</span>
	<span style="color: #800080;">$NodeToRead</span> <span style="color: pink;">=</span> <span style="color: #800080;">$CentralConfig</span>.SelectSingleNode<span style="color: #000000;">&#40;</span><span style="color: #800080;">$XPath</span><span style="color: #000000;">&#41;</span>
&nbsp;
	<span style="color: #008000;"># Read the current version</span>
	<span style="color: #800080;">$CurrentVersion</span> <span style="color: pink;">=</span> <span style="color: #800080;">$NodeToRead</span>.Value
	<span style="color: #800080;">$MajorVersion</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">Int</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$CurrentVersion</span>.Split<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;.&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #800080;">$MinorVersion</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">Int</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$CurrentVersion</span>.Split<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;.&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Current Version of Central Xml File: $CurrentVersion&quot;</span>
&nbsp;
	<span style="color: #008000;"># Backup central xml file</span>
	<span style="color: #800080;">$BackupFileName</span> <span style="color: pink;">=</span> <span style="color: #800080;">$CentralXmlFile</span>.Replace<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;.xml&quot;</span><span style="color: pink;">,</span> <span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;_{0}.xml&quot;</span> <span style="color: #FF0000;">-f</span> <span style="color: #800080;">$CurrentVersion</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #800080;">$CentralConfig</span>.Save<span style="color: #000000;">&#40;</span><span style="color: #800080;">$BackupFileName</span><span style="color: #000000;">&#41;</span>
&nbsp;
	<span style="color: #008000;"># Load personal xml file</span>
	<span style="color: #800080;">$PersonalConfig</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Xml.XmlDocument
	<span style="color: #800080;">$PersonalConfig</span>.Load<span style="color: #000000;">&#40;</span><span style="color: #800080;">$PersonalXmlFile</span><span style="color: #000000;">&#41;</span>
&nbsp;
	<span style="color: #008000;"># Select the correct node</span>
	<span style="color: #800080;">$NodeToBeChanged</span> <span style="color: pink;">=</span> <span style="color: #800080;">$PersonalConfig</span>.SelectSingleNode<span style="color: #000000;">&#40;</span><span style="color: #800080;">$XPath</span><span style="color: #000000;">&#41;</span>
&nbsp;
	<span style="color: #008000;"># Increment the version</span>
	<span style="color: #0000FF;">If</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$IncrementMinor</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><span style="color: #800080;">$MinorVersion</span><span style="color: pink;">++</span><span style="color: #000000;">&#125;</span>
	<span style="color: #0000FF;">If</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$IncrementMajor</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><span style="color: #800080;">$MajorVersion</span><span style="color: pink;">++</span>; <span style="color: #800080;">$MinorVersion</span> <span style="color: pink;">=</span> <span style="color: #804000;">0</span><span style="color: #000000;">&#125;</span>
	<span style="color: #800080;">$newVersion</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span>::Concat<span style="color: #000000;">&#40;</span><span style="color: #800080;">$MajorVersion</span><span style="color: pink;">,</span><span style="color: #800000;">&quot;.&quot;</span><span style="color: pink;">,</span><span style="color: #800080;">$MinorVersion</span><span style="color: #000000;">&#41;</span>
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;New Version of Central Xml File: $newVersion&quot;</span>
&nbsp;
	<span style="color: #008000;"># Write the new version</span>
	<span style="color: #800080;">$NodeToBeChanged</span>.Value <span style="color: pink;">=</span> <span style="color: #800080;">$newVersion</span>
&nbsp;
	<span style="color: #008000;"># Save the personal xml file as the new central xml file</span>
	<span style="color: #800080;">$PersonalConfig</span>.Save<span style="color: #000000;">&#40;</span><span style="color: #800080;">$CentralXmlFile</span><span style="color: #000000;">&#41;</span>	
	<span style="color: #000000;">&#125;</span></pre></div></div>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/powershell/increment-powergui-xml-version-with-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

