<?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>blog.powershell.no</title>
	<atom:link href="http://blog.powershell.no/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.powershell.no</link>
	<description>Read-Website -Type Blog -Topic PowerShell -Author &#039;Jan Egil Ring&#039;</description>
	<lastBuildDate>Wed, 22 May 2013 13:53:12 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5</generator>
		<item>
		<title>2013 Scripting Games &#8211; Learning points from Event 4</title>
		<link>http://blog.powershell.no/2013/05/22/2013-scripting-games-learning-points-from-event-4/</link>
		<comments>http://blog.powershell.no/2013/05/22/2013-scripting-games-learning-points-from-event-4/#comments</comments>
		<pubDate>Wed, 22 May 2013 13:51:01 +0000</pubDate>
		<dc:creator>Jan Egil Ring</dc:creator>
				<category><![CDATA[2013 Scripting Games Judges Notes]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Scripting Games]]></category>
		<category><![CDATA[Scripting Games 2013]]></category>
		<category><![CDATA[Windows PowerShell]]></category>
		<category><![CDATA[2013 scripting games event 4]]></category>

		<guid isPermaLink="false">http://blog.powershell.no/?p=24821</guid>
		<description><![CDATA[The 2013 Scripting Games started April 25th, and event 4 is now open for voting. As I did in the previous events, I will pick out two entries from each event and provide some learning points to highlight both good &#8230; <a href="http://blog.powershell.no/2013/05/22/2013-scripting-games-learning-points-from-event-4/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>The <a href="http://blog.powershell.no/2013/04/09/2013-scripting-games/">2013 Scripting Games</a> started April 25th, and event 4 is now <a href="http://scriptinggames.org/home.php">open for voting</a>. As I did in the <a href="http://blog.powershell.no/category/scripting-games-2013/2013-scripting-games-judges-notes/">previous events</a>, I will pick out two entries from each event and provide some learning points to highlight both good and bad practices.</p>
<p>Before reading my comments, you might want to download the event instructions:</p>
<ul>
<li><a href="http://scriptinggames.org/5e3cf97bca0e5716f3ee.pdf">Beginner 4: An Auditing Adventure</a></li>
<li><a href="http://scriptinggames.org/5d14fbd92df9e7409ba6.pdf">Advanced 4: An Auditing Adventure</a></li>
</ul>
<p>The first entry I will comment on is from Beginner 4:</p>
<script src="https://gist.github.com/5626326.js"></script><noscript><p>View the code on <a href="https://gist.github.com/5626326">Gist</a>.</p></noscript>
<ul>
<li><a href="http://technet.microsoft.com/en-us/library/hh847834.aspx">Comment based help</a> is leveraged to provide a synopsis, description and basic usage. Comment-based help and the Active Directory module which is leverage was introduced in PowerShell 2.0, thus #requires –version 2.0 could have been used to prevent users trying to run this in PowerShell 1.0 getting error messages.</li>
<li>HTML-formatting (head, pre- and post-content) as well as a couple of other variables is defined (note that I have updated <a href="http://blog.powershell.no/2013/05/16/2013-scripting-games-learning-points-from-event-3/">my previous article</a> with more info on working with HTML in PowerShell). I would also suggest the search base to be specified as a variable rather than a hard coded path in the script. Although, this is specifically stated in the synopsis.</li>
<li>The time stamp for when the report was created is included in the bottom of the report as required by the event instructions. In addition the username of the user generating the report is added, which is nice.</li>
<li>The actual cmdlets generating the report is a one-liner, nicely formatted on multiple lines for readability.</li>
<li>The lastlogon date property is used to determine when the users last logged on to the domain. There are ways to retrieve this information, and not all of them is accurate. For example the lastlogontimestamp property will be 9-14 days behind the current date. For more information, see <a href="http://blogs.technet.com/b/askds/archive/2009/04/15/the-lastlogontimestamp-attribute-what-it-was-designed-for-and-how-it-works.aspx">this article</a> on the “Ask the Directory Services Team” blog. To get a more accurate time stamp, you might want to query all domain controller, see <a href="http://technet.microsoft.com/en-us/library/dd378867(v=ws.10).aspx">this</a> TechNet article for one example on how to accomplish this. Although I would not withdraw any points for not catching this “gotcha”, I would give a bonus point for those who did.</li>
</ul>
<p>&nbsp;</p>
<p>The second entry I have decided to comment on is from Advanced 4:</p>
<script src="https://gist.github.com/5626670.js"></script><noscript><p>View the code on <a href="https://gist.github.com/5626670">Gist</a>.</p></noscript>
<ul>
<li>Leveraging the #requires statement is a good practice, however, this should be separated into two lines. When the script is run “as is” in PowerShell 2.0 the following error will be returned: “Cannot process the &#8220;#requires&#8221; statement at line 1 because it is not in the correct format.”. If separating into two lines, it will work in both 2.0 and 3.0:</li>
</ul>
<p>#Requires -Version 3.0<br />
#Requires -Module ActiveDirectory</p>
<ul>
<li><a href="http://technet.microsoft.com/en-us/library/hh847834.aspx">Comment based help</a> is leveraged in an excellent way, providing both help for all parameters as well as several examples.</li>
<li><a href="http://windowsitpro.com/blog/what-does-powershells-cmdletbinding-do">[CmdletBinding()]</a> is defined in order to use [Parameter()] decorators to validate input. Although there is nothing wrong with parameterizing this as a script, I would consider to turn it into a function (a personal preference).</li>
<li>The FilePath parameter is marked as mandatory, as well as positional. This is perfectly fine, but another option would be to default to a path using an environment variable (for example $env:userprofile\Documents\Report.html). The requirement of validating the filename extension (htm or html) is accomplished using a regular expression inside a ValidateScript validation.</li>
<li>The Count parameter is configured with a default value of 20 as required. In addition ValidateRange is leveraged to make sure the number specified is valid. This is not necessary, as defining the parameter as an integer would perform the necessary validation:</li>
</ul>
<p><em>Cannot convert value &#8220;2222222222222222&#8243; to type &#8220;System.Int32&#8243;. Error: &#8220;Value was<br />
either too large or too small for an Int32.</em></p>
<ul>
<li>Two additional parameters is supplied: One for overwriting the report-file if it exists (-Force) and one returning the newly created HTML file (-PassThru). These two parameters provide additional functionality not required by the instructions.</li>
<li>The parameter values for ConvertTo-Html is quite large, and providing these as a hashtable and leveraging splatting makes it more readable. This also makes it possible to collapse/expand the HTML-code (the hashtable) in PowerShell ISE.</li>
<li>The <a href="http://blogs.microsoft.co.il/blogs/scriptfanatic/archive/2012/04/13/Custom-objects-default-display-in-PowerShell-3-0.aspx">PSCustomObject</a> type accelerator is used to create new objects. There are many ways to create new objects in PowerShell 3.0, but this is the easiest/preferred way in my opinion. Also, the new <a href="http://mcpmag.com/articles/2012/12/11/pshell-order.aspx">[ordered]</a> type adapter in PowerShell 3.0 is leveraged to decide the order of the properties, rather than using Select-Object which will actually create new objects (<a href="http://www.jonathanmedd.net/2011/09/powershell-v3-creating-objects-with-pscustomobject-its-fast.html">more overhead</a>).</li>
</ul>
<p>Like the previous events, there have been many great submissions in event 4. Keep up the good work, and good luck with event 5 – “The Logfile Labyrinth”.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.powershell.no/2013/05/22/2013-scripting-games-learning-points-from-event-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>2013 Scripting Games &#8211; Learning points from Event 3</title>
		<link>http://blog.powershell.no/2013/05/16/2013-scripting-games-learning-points-from-event-3/</link>
		<comments>http://blog.powershell.no/2013/05/16/2013-scripting-games-learning-points-from-event-3/#comments</comments>
		<pubDate>Thu, 16 May 2013 21:35:52 +0000</pubDate>
		<dc:creator>Jan Egil Ring</dc:creator>
				<category><![CDATA[2013 Scripting Games Judges Notes]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Scripting Games]]></category>
		<category><![CDATA[Scripting Games 2013]]></category>
		<category><![CDATA[Windows PowerShell]]></category>
		<category><![CDATA[2013 scripting games event 3]]></category>

		<guid isPermaLink="false">http://blog.powershell.no/?p=24521</guid>
		<description><![CDATA[The 2013 Scripting Games started April 25th, and event 3 is now open for voting. As I did in the previous events, I will pick out two entries from each event and provide some learning points to highlight both good and &#8230; <a href="http://blog.powershell.no/2013/05/16/2013-scripting-games-learning-points-from-event-3/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>The <a href="http://blog.powershell.no/2013/04/09/2013-scripting-games/">2013 Scripting Games</a> started April 25th, and event 3 is now <a href="http://scriptinggames.org/home.php">open for voting</a>. As I did in the <a href="http://blog.powershell.no/category/scripting-games-2013/2013-scripting-games-judges-notes/">previous events</a>, I will pick out two entries from each event and provide some learning points to highlight both good and bad practices.</p>
<p>Before reading my comments, you might want to download the event instructions:</p>
<ul>
<li><a href="http://scriptinggames.org/cadfe0e7ccceb69ce7ac.pdf">Beginner 3: A Disk Decision</a></li>
<li><a href="http://scriptinggames.org/86122e78f3b1473045d1.pdf">Advanced 3: A Disk Decision</a></li>
</ul>
<p>The first entry I will comment on is from Beginner 3:</p>
<script src="https://gist.github.com/5594894.js"></script><noscript><p>View the code on <a href="https://gist.github.com/5594894">Gist</a>.</p></noscript>
<ul>
<li>Two pieces of information is required for this event, which we typically find in WMI. Since the instructions clearly stated that both CIM and WMI is available, and we do not have to think about authentication or firewalls, I find leveraging CIM a good practice. CIM is the newest technology, based on standards based management. It also requires just one firewall port to be open, compared to WMI which requires a lot more. Although, I would not give less points if WMI was leveraged in this event, since this is also a valid option in the instructions. In the real world however, we would typically need to think about authentication and firewalls in addition to other considerations, such as legacy systems. If Windows 2000 was still present, CIM would not have worked against WMI on that system without specifying the DCOM protocol for the CIM session.</li>
<li>Filtering is performed on the server side, which speeds up the query. A bad practice would have been skipping the –Filter parameter, and performed the filtering on the client side using Where-Object.</li>
<li>Extracting the data required by the instructions is done using Select-Object. What I also like is that formatting the data is done in the same operation. The –f operator is used to format the data, and PowerShell`s built-in constants for converting values to MB and GB is leveraged.</li>
<li>PowerShell has built-in capabilities to convert objects to HTML, in the form of the ConvertTo-Html cmdlet. This is leveraged in a way that meets the goals for the event instructions: The 3 properties needed is specified, and a header and a footer is added with the required data. However, a bonus point would have been added if the computer name was added to the header as specified in the event instructions. This is an example of how important it is to read the instructions carefully. I would recommend you to read through the instructions one more time before submitting your entry, as you might miss things like this.</li>
<li>The FilePath parameter is omitted on Out-File. This works fine since the parameter is positional. However, I prefer to use full parameter names when sharing scripts or even one-liners with others.</li>
<li>The instructions required a one-liner. Many people takes this literally, and place everything on one line. That is very bad for readability. This submission leverages the pipeline symbol, the comma and the back tick to continue on the next line. This is fully counted as a one-liner. However, the semi-colon as some people used does not qualify for a one-liner. This is simply a statement separator, and will break the pipeline.</li>
</ul>
<p>The second entry I have decided to comment on is from Advanced 3:</p>
<script src="https://gist.github.com/5595200.js"></script><noscript><p>View the code on <a href="https://gist.github.com/5595200">Gist</a>.</p></noscript>
<p>This entry does produce a nice looking HTML-report with the required data. However, there are some bad practices I would like to highlight as learning points:</p>
<ul>
<li>A ping function is created. This is not required, as PowerShell has a Test-Connection cmdlet giving the same functionality.</li>
<li>The naming of the function is not very descriptive for the end user sitting at the helpdesk.</li>
<li>The HTML code is created in a here-string rather than leveraging PowerShell`s ConvertTo-Html cmdlet. This makes it harder than necessary.</li>
<li>Aliases is used. This is ok when working interactively when you want to type fast, but not in a script or function you will share with others (think readability).</li>
<li>Write-Host is used (don`t kill puppies), use Write-Verbose to output additional information. Alternatively, output an object even if the computer could not be contacted. You could add a “Connectivity” property to inform the user whether the computer was reachable or not, and add this to the report.</li>
</ul>
<p>There have been many great suggestions in this event. Keep up the good work, and good luck with event 4 – <a href="http://scriptinggames.org/home.php">“An Auditing Adventure”.</a></p>
<p><span style="text-decoration: underline;">Update 2013-05-21:</span> The good thing about the Scripting Games is that everyone learns something, including the judges. I haven`t been using here-strings for creating HTML, but as Rob Campbell (@mjolinor) <a href="https://twitter.com/mjolinor/status/335195022569926658">stated</a> on Twitter: &#8220;Here strings are an AWESOME tool for creating HTML or XML documents. &#8221; -Jeffrey Snover. (<a href="http://blogs.msdn.com/b/powershell/archive/2006/07/15/variable-expansion-in-strings-and-herestrings.aspx">link</a>). Of course, this implies that you <em>know</em> HTML. On the topic of HTML, I would also like to recommend Don Jones` free ebook &#8220;<a href="http://powershell.org/wp/2012/04/21/powershell-book-recommendations/">Creating HTML Reports in PowerShell</a>&#8220;. Available with the book is also a PowerShell module for working with HTML. In addition, there is also a very good session recording from the 2013 PowerShell Summit by Jeffrey Hicks called &#8220;<a href="http://www.youtube.com/watch?v=pL_Ry5LzX3w">Creating HTML Reports With style</a>&#8220;.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.powershell.no/2013/05/16/2013-scripting-games-learning-points-from-event-3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>2013 Scripting Games &#8211; Learning points from Event 2</title>
		<link>http://blog.powershell.no/2013/05/08/2013-scripting-games-learning-points-from-event-2/</link>
		<comments>http://blog.powershell.no/2013/05/08/2013-scripting-games-learning-points-from-event-2/#comments</comments>
		<pubDate>Wed, 08 May 2013 19:16:53 +0000</pubDate>
		<dc:creator>Jan Egil Ring</dc:creator>
				<category><![CDATA[2013 Scripting Games Judges Notes]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Scripting Games 2013]]></category>
		<category><![CDATA[Windows PowerShell]]></category>
		<category><![CDATA[scripting games 2013; event 2]]></category>

		<guid isPermaLink="false">http://blog.powershell.no/?p=24161</guid>
		<description><![CDATA[The 2013 Scripting Games started April 25th, and event 2 is now open for voting. As I did in event 1, I will pick out two entries from each event and provide some learning points to highlight both good and &#8230; <a href="http://blog.powershell.no/2013/05/08/2013-scripting-games-learning-points-from-event-2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>The <a href="http://blog.powershell.no/2013/04/09/2013-scripting-games/">2013 Scripting Games</a> started April 25th, and event 2 is now <a href="http://scriptinggames.org/home.php">open for voting</a>. As I did in <a href="http://blog.powershell.no/2013/05/01/2013-scripting-games-learning-points-from-event-1/">event 1</a>, I will pick out two entries from each event and provide some learning points to highlight both good and bad practices.</p>
<p>Before reading my comments, you might want to download the event instructions:</p>
<ul>
<li><a href="http://scriptinggames.org/4192a33d2c7d3ad28bdf.pdf">Beginner 2: An Inventory Intervention</a></li>
<li><a href="http://scriptinggames.org/4eab84e486ddf9144ed9.pdf">Advanced 2: An Inventory Intervention</a></li>
</ul>
<p>The first entry I will comment on is from Beginner 2:</p>
<script src="https://gist.github.com/5542568.js"></script><noscript><p>View the code on <a href="https://gist.github.com/5542568">Gist</a>.</p></noscript>
<p>Note: I am testing <a href="http://en.support.wordpress.com/gist/">Gist</a> as a way to share code snippets. I may need to edit the article after posting, please refresh your browser or go to the Gist URL manually if you do not see the code.</p>
<style type="text/css"><!--
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
--></style>
<ul>
<li>I find using [System.Net.Dns]::GetHostEntry unnecessary in this case, as the name of the computers will be available from the WMI calls being used.</li>
<li>Whether to use the foreach statement or the ForEach-Object cmdlet is not that relevant in this case, as saving the contents of a small text-file into memory does not consume much resources.<br />
However, using Foreach-Object two times is unnecessary, there is nothing that prevents wrapping everything in one foreach-loop.</li>
<li>The event instructions did not require you to provide alternate credentials. Since it is done anyway in this submission, I would rather save the credentials into a variable once and re-use that variable inside the foreach-loop. If not, the user will be prompted for credentials two times for each computer in the text-file.</li>
<li>Re-writing the property names in the last line to make them more user-friendly is good, but there are some room for improvement in this line as well. Consider using Select-Object instead of Format-Table, this will make it up to the user what to do with the output. For example outputting them to a Csv-file using Export-Csv, or creating an HTML-report using ConvertTo-Html. Consider breaking the line into multiple lines to make it easier to read. Do not use aliases (ft in this case) when sharing a script, this makes it harder to read. Aliases are good though, when you work interactively in the shell and want to type as quickly as possible.</li>
</ul>
<p>The second entry I have decided to comment on is from Advanced 2:</p>
<script src="https://gist.github.com/5542478.js"></script><noscript><p>View the code on <a href="https://gist.github.com/5542478">Gist</a>.</p></noscript>
<ul>
<li>The use of the <a href="http://technet.microsoft.com/en-us/library/hh847765.aspx">#requires statement</a> is good, since this function leverages new functionality in PowerShell 3.0 which would have caused errors in previous versions of PowerShell.</li>
<li><a href="http://technet.microsoft.com/en-us/library/hh847834.aspx">Comment based help</a> is leveraged in an excellent way, showing a very detailed description, help for each parameter, several examples, and what kind of object the function accepts as input and produces as output. .PARAMETER ShowProtocol is missing, although this parameter is documented in the description.</li>
<li>The function accepts input from the pipeline by using [Parameter(ValueFromPipeline=$True)], which makes it possible to pipe the contents of a txt-file to the function as shown in one of the examples.</li>
<li>A new Cim Session Option object is created in the begin block, defining DCOM as the protocol. This is a good example of showing how to use the begin block, which is typically used for operations that needs to be performed once for all of the objects that will be processed in the process block. One of the most common examples of using the begin block is connecting to a database server, but this function also shows another usage scenario.</li>
<li>The <a href="http://blogs.msdn.com/b/powershell/archive/2012/08/24/introduction-to-cim-cmdlets.aspx">new CIM cmdlets</a> in PowerShell 3.0 is leveraged when WSMAN 3.0 is available, if not the legacy DCOM protocol is used. This way, the function will work against both newer systems like Windows Server 2012 as well as older systems like Windows 2000 Server. As stated in the description, “The Cim cmdlets have been used to gain maximum efficiency so only one connection will be made to each computer.”.</li>
<li><a href="http://technet.microsoft.com/en-us/library/hh847793.aspx">Error handling</a> is implemented, ensuring that even if the function is unable to connect to a computer, an object is returned stating that it was not possible to connect to the computer.</li>
<li><a href="http://technet.microsoft.com/en-us/magazine/gg675931.aspx">Splatting</a> is leveraged for passing parameters, see examples on line 71 and line 95.</li>
<li>The function is outputting a custom object rather than text or formatting objects. This makes it up to the user using the function to decide what to do with the data. The <a href="http://mcpmag.com/articles/2012/12/11/pshell-order.aspx">new [ordered] syntax</a> in PowerShell 3.0 is leveraged when creating the hash table which is passed to New-Object, in order to control the order of the properties of the custom object.</li>
</ul>
<p>It has been fun to read through many of the great submissions made to event 2. Keep up the good work, and good luck with event 3 which starts May 9th.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.powershell.no/2013/05/08/2013-scripting-games-learning-points-from-event-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>2013 Scripting Games &#8211; Learning points from Event 1</title>
		<link>http://blog.powershell.no/2013/05/01/2013-scripting-games-learning-points-from-event-1/</link>
		<comments>http://blog.powershell.no/2013/05/01/2013-scripting-games-learning-points-from-event-1/#comments</comments>
		<pubDate>Wed, 01 May 2013 11:14:12 +0000</pubDate>
		<dc:creator>Jan Egil Ring</dc:creator>
				<category><![CDATA[2013 Scripting Games Judges Notes]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Scripting Games]]></category>
		<category><![CDATA[Scripting Games 2013]]></category>
		<category><![CDATA[Windows PowerShell]]></category>
		<category><![CDATA[scripting games 2013]]></category>

		<guid isPermaLink="false">http://blog.powershell.no/?p=23961</guid>
		<description><![CDATA[The 2013 Scripting Games started April 25th, and event 1 is now open for voting. As I am participating as a judge this year, I will pick out two entries from each event and provide some learning points to highlight &#8230; <a href="http://blog.powershell.no/2013/05/01/2013-scripting-games-learning-points-from-event-1/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>The <a href="http://blog.powershell.no/2013/04/09/2013-scripting-games/">2013 Scripting Games</a> started April 25th, and event 1 is now <a href="http://scriptinggames.org/home.php">open for voting</a>. As I am participating as a <a href="http://powershell.org/wp/2013/04/06/2013-scripting-games-judges/">judge</a> this year, I will pick out two entries from each event and provide some learning points to highlight both good and bad practices.</p>
<p>The first entry I have decided to comment on is from <a href="http://scriptinggames.org/entrylist.php?eventid=11">Beginner 1: An Archival Atrocity</a>.</p>
<pre class="csharpcode">$RootPath = <span class="str">"C:\ScriptingGames\Application\Log"</span>
$Paths = Get-ChildItem $RootPath
$ArchivePath = <span class="str">"C:\ScriptingGames\Archive"</span>
$varTime = (Get-Date).Adddays(-90)

ForEach ($Path <span class="kwrd">in</span> $Paths)
{
    If ((Test-Path <span class="str">"$ArchivePath\$Path"</span>) <span class="preproc">-eq</span> <span class="str">"True"</span>)
        {
            Echo <span class="str">"Path Exists"</span>
        }
    Else
        {
            Echo <span class="str">"$Path Created"</span>
            Mkdir <span class="str">"$ArchivePath\$Path"</span>
        }
    
        Get-ChildItem -literalpath <span class="str">"$RootPath\$path"</span> -Include <span class="str">"*.*"</span> -Recurse | Where-Object {$_.CreationTime <span class="preproc">-lt</span> <span class="str">"$varTime"</span>} | Move-Item -Destination "$ArchivePath\$path\" 
}</pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<h1>Learning Points</h1>
<ul>
<li>Add comment based help. This makes it more easy for others to leverage the script, you also get the benefit of using Get-Help on your function or script.
<li>The instructions did not require any output, consider using Write-Verbose instead of Write-Output. This makes it up to the user leveraging the script to decide if any output is wanted, by editing the <a href="http://technet.microsoft.com/en-us/library/hh847796.aspx">$VerbosePreference</a> automatic variable.
<li>Avoid using aliases in scripts (Echo and Mkdir in this case), although it is great for interactive use when you want to type quickly.
<li>When sharing a script, I also prefer to use full parameter names. For example Get-ChildItem -Path $RootPath instead of Get-ChildItem $RootPath.</li>
</ul>
<p>The second entry is from <a href="http://scriptinggames.org/entrylist.php?eventid=12">Advanced 1: An Archival Atrocity</a>.</p>
<pre class="csharpcode"><span class="kwrd">function</span> Move-Log{
&lt;<span class="rem">#</span>
.SYNOPSIS
Moves old log files <span class="kwrd">in</span> the specified repository to another location.

.DESCRIPTION
Move-Log is used to move old log files from specified application folders <span class="kwrd">in</span> a root log repository to a new location. 
By <span class="kwrd">default</span> only files older than 90 days are moved, but this can be configured with the -Period parameter.
Subfolder structure is mantained <span class="kwrd">in</span> the destination path.

.PARAMETER LogPath
Specifies the root path of the log repository.
Default = C:\Application\Log

.PARAMETER ApplicationLogFolder
Specifies application folders <span class="kwrd">in</span> the log repository that may contain log files.

.PARAMETER DestinationPath
Specifies the new location <span class="kwrd">for</span> the log files.

.PARAMETER Period
Specifies how old, <span class="kwrd">in</span> days, must be the log files to be moved.
Default = 90

.EXAMPLE
Move-Log -ApplicationLogFolder App1, OtherApp, ThisAppAlso -DestinationPath \\NASServer\Archives

This will move files older than 90 day located <span class="kwrd">in</span> <span class="str">"C:\Application\Log\App1"</span>, <span class="str">"C:\Application\Log\OtherApp"</span> and <span class="str">"C:\Application\Log\ThisAppAlso"</span> 
to their respective destination folders <span class="str">"\\NASServer\Archives\App1"</span>, <span class="str">"\\NASServer\Archives\OtherApp"</span> and <span class="str">"\\NASServer\Archives\ThisAppAlso"</span>.

.EXAMPLE
Move-Log -LogPath C:\MyLogRepository\ -ApplicationLogFolder App1,OtherApp,ThisAppAlso -DestinationPath \\NASServer\Archives -Period 365

This will move files older than 1 year from <span class="str">"C:\MyLogRepository\App1"</span>, <span class="str">"C:\MyLogRepository\OtherApp"</span> and <span class="str">"C:\MyLogRepository\ThisAppAlso"</span> 
to their respective destination folders <span class="str">"\\NASServer\Archives\App1"</span>, <span class="str">"\\NASServer\Archives\OtherApp"</span> and <span class="str">"\\NASServer\Archives\ThisAppAlso"</span>.

.INPUTS
None.
.OUTPUTS
None.
<span class="rem">#&gt;</span>
    [CmdletBinding()]
    <span class="kwrd">param</span>(
    [ValidateScript({ Test-Path $_ -PathType Container })]
    [string]$LogPath=<span class="str">"C:\Application\Log"</span>,
    [Parameter(Mandatory=$true)]
    [ValidateScript({ Test-Path <span class="str">"$LogPath\*"</span> -Include $_ -PathType Container })]
    [string[]]$ApplicationLogFolder,   
    [Parameter(Mandatory=$true)] 
    [ValidateScript({ Test-Path $_ -PathType Container })]
    [string]$DestinationPath,
    [int]$Period=90
    ) 
    
    <span class="rem"># Get the date limit. Only files older than that date will be moved    </span>
    $DateLimit = (Get-Date).AddDays(-$Period)

    <span class="kwrd">foreach</span> ($AppFolder <span class="kwrd">in</span> $ApplicationLogFolder)
    {
        $AppLogPath      = <span class="str">"$LogPath\$AppFolder"</span>
        $DestAppLogPath  = <span class="str">"$DestinationPath\$AppFolder"</span>

        <span class="rem"># Create destination folder if not exists</span>
        <span class="kwrd">if</span> (!(Test-Path $DestAppLogPath -PathType Container))
        {
            try
            {
                New-Item -Path $DestAppLogPath -ItemType Directory -ErrorAction Stop -ErrorVariable $DirectoryError
            }
            catch
            {
                Write-Error <span class="str">"Error creating destination directory $DestAppLogPath. Error: $DirectoryError"</span>  
                <span class="rem"># Jump to the next $AppFolder              </span>
                <span class="kwrd">continue</span>
            }
        }

        <span class="rem"># Get the name of the files to move</span>
        $FilesToMove = Get-ChildItem $AppLogPath -File | Foreach { <span class="kwrd">if</span> ($_.LastWriteTime <span class="preproc">-lt</span> $DateLimit) { $_.Name } }

        <span class="kwrd">foreach</span> ($File <span class="kwrd">in</span> $FilesToMove)
        {
            $FilePath = <span class="str">"$AppLogPath\$File"</span>
            $DestPath  = <span class="str">"$DestAppLogPath\$File"</span>

            <span class="rem"># Move the file</span>
            try
            {
                Move-Item -Path $FilePath -Destination $DestPath -ErrorAction Stop -ErrorVariable $MoveError
            }
            catch
            {
                Write-Error <span class="str">"Error moving file $FilePath to destination $DestPath. Error: $MoveError"</span>
            }
        }
    }     
}</pre>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<h1>Learning Points</h1>
<ul>
<li>The use of a function makes this tool easier to reuse without the need to call a script each time.
<li>The use of an advanced function makes it work more like an actual cmdlet, since you can do more advanced things such as marking a parameter as mandatory and validating the arguments. For more information, see Get-Help <a href="http://technet.microsoft.com/en-us/library/hh847806.aspx">about_Functions_Advanced</a>.
<li>This is also a good example on leveraging <a href="http://technet.microsoft.com/en-us/library/hh847834.aspx">comment based help</a>. All parameters is properly described, and a few examples is provided. Often the first thing people look at before reading the actual help is the examples, so it is important to provide at least a couple of them.
<li>The use of <a href="http://blogs.technet.com/b/heyscriptingguy/archive/2011/05/15/simplify-your-powershell-script-with-parameter-validation.aspx">parameter validation</a> is excellent, as this simplifies the function and is leveraging functionality PowerShell is providing &#8220;for free&#8221;.
<li>Default values is configured for the LogPath and Period parameters. This means that these parameter values will be used if the user using the function does not specify these parameters. It is also easy to change the values if needed, which was a requirement for this task.</li>
</ul>
<p>There have been many great submissions for the first event. Keep up the good work, and good luck with event 2 which starts May 2.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.powershell.no/2013/05/01/2013-scripting-games-learning-points-from-event-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>2013 Scripting Games</title>
		<link>http://blog.powershell.no/2013/04/09/2013-scripting-games/</link>
		<comments>http://blog.powershell.no/2013/04/09/2013-scripting-games/#comments</comments>
		<pubDate>Tue, 09 Apr 2013 14:58:16 +0000</pubDate>
		<dc:creator>Jan Egil Ring</dc:creator>
				<category><![CDATA[2013 Scripting Games Judges Notes]]></category>
		<category><![CDATA[Scripting Games 2013]]></category>
		<category><![CDATA[Windows PowerShell]]></category>
		<category><![CDATA[powershell;scripting games]]></category>

		<guid isPermaLink="false">http://blog.powershell.no/?p=22261</guid>
		<description><![CDATA[The 2013 Scripting Games is starting April 25th. Unlike previous years, the event is no longer run by Microsoft. It is now managed by the community-owned corporation PowerShell.org, but it is still supported by Microsoft and the Scripting Guys. There &#8230; <a href="http://blog.powershell.no/2013/04/09/2013-scripting-games/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>The 2013 Scripting Games is starting April 25th. Unlike previous years, the event is no longer run by Microsoft. It is now managed by the community-owned corporation <a href="http://powershell.org/">PowerShell.org</a>, but it is still supported by Microsoft and the <a href="http://blogs.technet.com/b/heyscriptingguy/">Scripting Guys</a>.</p>
<p>There are also some differences in how the games is run. Previously, only the jugdes could assign scores. Now everyone can vote on submitted scripts, while the judges will review and comment on selected submissions. I highly encourage you to read the Competitor Guide (link in the resource section below), which is a PDF-file with all the information you need to know in terms of the games.</p>
<p>I will participating as a <a href="http://powershell.org/wp/2013/04/06/2013-scripting-games-judges/">judge</a>, and I am really looking forward to writing articles about some of the submissions.</p>
<p>Whether you are a beginner in terms of using Windows PowerShell, or an experienced scripter, the scripting games is a perfect opportunity to challenge yourself and get feedback on your work. Remember, the key point about the games is <em>learning</em>. Good luck to all participants!</p>
<p><strong>2013 Scripting Games Resources</strong></p>
<ul>
<li><a href="http://powershell.org/games/2013CompetitorGuide.pdf">2013 Competitor Guide</a></li>
<li><a href="http://powershell.org/wp/2013/04/03/2013-scripting-games-schedule/">2013 Scripting Games schedule</a></li>
<li><a href="http://powershell.org/wp/category/announcements/scripting-games/">Scripting Games Announcement Channel</a></li>
<li><a href="http://powershell.org/wp/category/announcements/scripting-games/judges-notes/">Scripting Games Judges Notes</a></li>
<li>Twitter hashtag: <a href="https://twitter.com/search/realtime?q=#Psh2013">#Psh2013</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.powershell.no/2013/04/09/2013-scripting-games/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Converting Hyper-V VHD-files to VHDX using Windows PowerShell</title>
		<link>http://blog.powershell.no/2013/04/07/converting-hyper-v-vhd-files-to-vhdx-using-windows-powershell/</link>
		<comments>http://blog.powershell.no/2013/04/07/converting-hyper-v-vhd-files-to-vhdx-using-windows-powershell/#comments</comments>
		<pubDate>Sun, 07 Apr 2013 07:15:00 +0000</pubDate>
		<dc:creator>Jan Egil Ring</dc:creator>
				<category><![CDATA[Hyper-V]]></category>
		<category><![CDATA[Virtualization]]></category>
		<category><![CDATA[Windows 8]]></category>
		<category><![CDATA[Windows PowerShell]]></category>
		<category><![CDATA[Windows PowerShell 3.0]]></category>
		<category><![CDATA[Windows Server 2012]]></category>
		<category><![CDATA[powershell;vhd;vhdx]]></category>

		<guid isPermaLink="false">http://blog.powershell.no/?p=21941</guid>
		<description><![CDATA[With the introduction of Windows Server 2012 Hyper-V, Microsoft also provided a new format for virtual hard disk files. The previous VHD-format is now updated to a new format called VHDX. Some of the new features of the new format &#8230; <a href="http://blog.powershell.no/2013/04/07/converting-hyper-v-vhd-files-to-vhdx-using-windows-powershell/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>With the introduction of Windows Server 2012 Hyper-V, Microsoft also provided a new format for virtual hard disk files. The previous VHD-format is now updated to a new format called VHDX. Some of the new features of the new format is much larger storage capacity (from a maximum of 2 TB for VHD, to a new maximum of 64 TB for VHDX), as well as data corruption protection during power failures. You can find more information about the new VHDX format on the “<a href="http://technet.microsoft.com/en-us/library/hh831446.aspx">Hyper-V Virtual Hard Disk Format Overview</a>” article on Microsoft TechNet, as well as the “<a href="http://www.microsoft.com/en-us/download/details.aspx?id=34750">VHDX Format Specification v 1.0</a>” document which provides detailed information.</p>
<p>When virtual machines are migrated (imported) to a Windows Server 2012 Hyper-V host, the virtual hard disk files is not automatically converted to the new VHDX format. This is something you must do manually, either by using the “Edit Virtual Hard Disk Wizard” or by using the <a href="http://technet.microsoft.com/en-us/library/hh848454(v=wps.620).aspx">Convert-VHD</a> cmdlet in the <a href="http://technet.microsoft.com/en-us/library/jj136050.aspx">Hyper-V PowerShell module</a>.</p>
<p>As soon as a virtual machine is migrated from an earlier version of Hyper-V to Windows Server 2012 Hyper-V, best practice would be to convert the virtual hard disk files to the new VHDX format.</p>
<p>If you have more than a couple of virtual machines, it would be a good idea to automate the conversion process. You can start to explore the Convert-VHD cmdlet by running Get-Help &#8220;Convert-VHD&#8221; –ShowWindow:</p>
<p><a href="http://blog.powershell.no/wp-content/uploads/2013/04/image.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://blog.powershell.no/wp-content/uploads/2013/04/image_thumb.png" width="453" height="353" border="0" /></a></p>
<p>If you do not get a similar result as above, run Update-Help from an elevated PowerShell session and try again.</p>
<p>If you scroll to the bottom you will also find a few examples:</p>
<p><a href="http://blog.powershell.no/wp-content/uploads/2013/04/image1.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;" title="image" alt="image" src="http://blog.powershell.no/wp-content/uploads/2013/04/image_thumb1.png" width="455" height="183" border="0" /></a></p>
<p>Example 1 shows how to convert a single VHD file to a new VHDX file. There are several things to consider before doing this in a production environment:</p>
<ul>
<li>Should you keep the source VHD in case something goes wrong? If no, add the –DeleteSource swich parameter.</li>
<li>Should you use Fixed disks or Dynamically expanding disks? There are different recommendations both in the community and in Microsoft. In the <a href="http://msdn.microsoft.com/en-us/library/windows/hardware/jj248719.aspx">Performance Tuning Guidelines for Windows Server 2012</a> dynamically expanding is recommended, while in this Premier Field Engineering (PFE) blog article Fixed size is recommended. To read more opinions from the community, see <a href="http://www.aidanfinn.com/?p=14288">this article</a> by Virtual Machine MVP Aidan Finn as well as <a href="http://www.thomasmaurer.ch/2012/11/windows-server-2012-hyper-v-virtual-disk-vhd-vhdx-recommendations/">this article</a> by Virtual Machine MVP Thomas Maurer.</li>
<li>The virtual machine must be stop before its virtual hard disk files can be expanded.</li>
<li>The old VHD file must be replaced by the new VHDX file in the virtual machine configuration.</li>
<li>Enough disk space must be available on the underlying data disk. For example, if the VHD file to be converted is 100 GB, you must have minimum 100 GB free space on the data disk for the destination VHDX file.</li>
</ul>
<p>I have created a sample PowerShell script below which will convert VHD-files for stopped virtual machines to VHDX. If the virtual hard disk files for the stopped virtual machines is already of type VHDX, the virtual machine will be skipped.</p>
<style type="text/css"><!--
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
--></style>
<p>You may want to add additional logging and error handling before using this script in a production environment. I would also encourage to always test the script in a lab environment before using it in production.</p>
<p>You can find the script <a href="http://gallery.technet.microsoft.com/scriptcenter/Converting-Hyper-V-VHD-550b9467">here</a> on the Microsoft TechNet Script Center.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.powershell.no/2013/04/07/converting-hyper-v-vhd-files-to-vhdx-using-windows-powershell/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Automatically update help-files for Windows PowerShell</title>
		<link>http://blog.powershell.no/2013/03/09/automatically-update-help-files-for-windows-powershell/</link>
		<comments>http://blog.powershell.no/2013/03/09/automatically-update-help-files-for-windows-powershell/#comments</comments>
		<pubDate>Sat, 09 Mar 2013 15:37:51 +0000</pubDate>
		<dc:creator>Jan Egil Ring</dc:creator>
				<category><![CDATA[Windows PowerShell]]></category>
		<category><![CDATA[Windows PowerShell 3.0]]></category>
		<category><![CDATA[PowerShell Updateable Help System]]></category>
		<category><![CDATA[Save-Help]]></category>
		<category><![CDATA[Update-Help]]></category>

		<guid isPermaLink="false">http://blog.powershell.no/?p=19381</guid>
		<description><![CDATA[With the introduction of Windows PowerShell 3.0 the help system was made updateable, which means we no longer have to wait for the next release of PowerShell to retrieve enhancements and bug fixes to the help system. In an enterprise &#8230; <a href="http://blog.powershell.no/2013/03/09/automatically-update-help-files-for-windows-powershell/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>With the introduction of Windows PowerShell 3.0 the help system was made updateable, which means we no longer have to wait for the next release of PowerShell to retrieve enhancements and bug fixes to the help system.</p>
<p>In an enterprise environment the help system typically needs to be centrally managed. There are several ways to accomplish this, for example we can use the &#8220;Set the default source path for Update-Help&#8221; Group Policy setting under Computer Configuration-&gt;Administrative Templates-&gt;Windows Components-&gt;Windows PowerShell to specify a default value for the SourcePath parameter:</p>
<p><a href="http://blog.powershell.no/wp-content/uploads/2013/03/image.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blog.powershell.no/wp-content/uploads/2013/03/image_thumb.png" width="390" height="359"></a></p>
<p>In order to automatically update help files on computers running PowerShell 3.0 we can leverage scheduled tasks and distribute these through Group Policy.</p>
<p>1) On a computer running Windows Server 2012 or Windows 8, create a scheduled task that will periodically run the Save-Help cmdlet to save the files to a central location. This is not mandatory, but typically large environments have computers without internet access, thus it may be appropriate to download the help files to a central file server. In order to retrieve help files for all modules you should also install all management tools from Server Manager on the Windows Server 2012 computer running the scheduled task (using Remote Server Administration Tools if running Windows 8). Note that there is a HelpModules available which removes the requirement to install the management tools made by PowerShell MVP Joel “Jaykul” Bennett. You can read more in his blog post “<a href="http://huddledmasses.org/get-help-for-modules-you-dont-have-installed/">Get-Help for Modules you don’t have installed</a>”.</p>
<p>Create a new scheduled task which runs with the computer account`s credentials (SYSTEM):</p>
<p><a href="http://blog.powershell.no/wp-content/uploads/2013/03/image1.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blog.powershell.no/wp-content/uploads/2013/03/image_thumb1.png" width="390" height="289"></a> </p>
<p>Note: Remember to configure the file and NTFS settings for the central file share to allow Domain Computers to read the files.
<p>Next, configure an appropriate time when the scheduled task should run:</p>
<p><a href="http://blog.powershell.no/wp-content/uploads/2013/03/image2.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blog.powershell.no/wp-content/uploads/2013/03/image_thumb2.png" width="389" height="289"></a> </p>
<p>Configure an action with the Start a program option:</p>
<p><a href="http://blog.powershell.no/wp-content/uploads/2013/03/image3.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blog.powershell.no/wp-content/uploads/2013/03/image_thumb3.png" width="387" height="287"></a> </p>
<p>Path: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe<br />Arguments: -Command &#8220;&amp; {Update-Help;Save-Help -DestinationPath &#8216;\\server\share\PowerShell\Help-files&#8217;}&#8221;
<p>This will first run Update-Help to retrieve the newest help-files from Microsoft, and Save-Help to save the help-files from the local computer to the central file share.
<p>Note: You could also use PowerShell to create the scheduled task which will run Save-Help, an example can be found in <a href="http://www.ehloworld.com/1731">this</a> blog post by Pat Richard.
<p>2) On a Group Policy object which will affect all computers where you want the help files to be deployed, create a new scheduled task using Group Policy Preferences:</p>
<p><a href="http://blog.powershell.no/wp-content/uploads/2013/03/image4.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blog.powershell.no/wp-content/uploads/2013/03/image_thumb4.png" width="152" height="244"></a></p>
<p>Create a new scheduled task which runs with the computer account`s credentials (SYSTEM):</p>
<p><a href="http://blog.powershell.no/wp-content/uploads/2013/03/image5.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blog.powershell.no/wp-content/uploads/2013/03/image_thumb5.png" width="390" height="289"></a></p>
<p>Next, configure an appropriate time when the scheduled task should run (this should run shortly after the Save-Help scheduled task is run):</p>
<p><a href="http://blog.powershell.no/wp-content/uploads/2013/03/image6.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blog.powershell.no/wp-content/uploads/2013/03/image_thumb6.png" width="385" height="286"></a></p>
<p>Configure an action with the Start a program option:</p>
<p><a href="http://blog.powershell.no/wp-content/uploads/2013/03/image7.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blog.powershell.no/wp-content/uploads/2013/03/image_thumb7.png" width="385" height="287"></a></p>
<p>Path: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe<br />Arguments: -Command &#8220;&amp; {if (($PSVersionTable.PSVersion).Major -ge 3) {Update-Help -SourcePath &#8216;\\server\share\PowerShell\Help-files&#8217;}}&#8221;</p>
<p>You could also use Item-level targeting in order to create the scheduled task only on computers where PowerShell 3.0 is installed (if doing so, the if (($PSVersionTable.PSVersion).Major statement above can be dropped):</p>
<p><a href="http://blog.powershell.no/wp-content/uploads/2013/03/image8.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blog.powershell.no/wp-content/uploads/2013/03/image_thumb8.png" width="251" height="114"></a></p>
<p>Here we test if the key named “3” exists under the PowerShell hive in HKLM:</p>
<p><a href="http://blog.powershell.no/wp-content/uploads/2013/03/image9.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blog.powershell.no/wp-content/uploads/2013/03/image_thumb9.png" width="439" height="172"></a></p>
<p>Finally the task is created:</p>
<p><a href="http://blog.powershell.no/wp-content/uploads/2013/03/image10.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blog.powershell.no/wp-content/uploads/2013/03/image_thumb10.png" width="244" height="51"></a></p>
<p>When future PowerShell versions is released, for example PowerShell 4.0, the Item level targeting must be updated to check for the “4” key in the registry as well. Alternatively an even more clever method to determine that the minimum version of PowerShell is 3.0 may be incorporated (please leave a note in the comments section below if you create one).</p>
<p><strong>Resources</strong></p>
<ul>
<li><a href="http://technet.microsoft.com/en-us/library/hh847735.aspx">about_Updatable_Help</a>
<li><a href="http://blogs.technet.com/b/heyscriptingguy/archive/2012/08/31/understanding-and-using-updatable-powershell-help.aspx">Understanding and Using Updatable PowerShell Help</a>
<li><a href="http://msdn.microsoft.com/en-us/library/windows/desktop/hh852752(v=vs.85).aspx">How Updatable Help Works</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.powershell.no/2013/03/09/automatically-update-help-files-for-windows-powershell/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Videos from Nordic Infrastructure Conference 2013</title>
		<link>http://blog.powershell.no/2013/02/06/videos-from-nordic-infrastructure-conference-2013/</link>
		<comments>http://blog.powershell.no/2013/02/06/videos-from-nordic-infrastructure-conference-2013/#comments</comments>
		<pubDate>Wed, 06 Feb 2013 18:00:27 +0000</pubDate>
		<dc:creator>Jan Egil Ring</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[Windows PowerShell]]></category>
		<category><![CDATA[Nordic Infrastructure Conference]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://blog.powershell.no/?p=17731</guid>
		<description><![CDATA[On January 24th – 25th the Nordic Infrastructure Conference (NIC) was arranged in Oslo, Norway for the second time. The goal for the conference is creating a premier event for all IT-professionals in the Nordics, and like the first edition &#8230; <a href="http://blog.powershell.no/2013/02/06/videos-from-nordic-infrastructure-conference-2013/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>On January 24th – 25th the Nordic Infrastructure Conference (<a href="http://www.nic2012.com/about_nic_2012">NIC</a>) was arranged in Oslo, Norway for the second time. The goal for the conference is creating a premier event for all IT-professionals in the Nordics, and like the first edition of NIC, the second edition was also a great success with a number of excellent <a href="http://nicconf.com/program/speakers">speakers.</a> Featured speakers includes <a href="http://nicconf.com/program/jeffrey-snover">Jeffrey Snover</a>, <a href="http://nicconf.com/program/wally-mead">Wally Mead</a> and <a href="http://nicconf.com/program/scott-schnoll">Scott Schnoll</a>.</p>
<p>I did a session together with my colleague at Crayon Norway, Ingar Kopperud, called “Configuration Manager 2012 &#8211; Automation using PowerShell”. In the session we provided an overview of the new Windows PowerShell module in Configuration Manager 2012 SP1 before we looked at automation of the initial configuration of a Configuration Manager infrastructure. After that we showed how to automate deployment of distribution points, before we ended the session by showing how to automate application deployment. The session was very demo focused, thus we had only 3 slides in our presentation. The slides is available <a href="http://www.slideshare.net/janegilring/configuration-manager-2012-automation-using-powershell">here</a>, while the video recording is available <a href="https://vimeo.com/58165668">here.</a>
<p>Video recordings of all the other sessions at NIC 2013 is available <a href="http://nicconf.com/nic2013_agenda">here</a> (there is a “click to view video” link for each session).</p>
<p><strong>PowerShell related videos</strong></p>
<ul>
<li><a href="https://vimeo.com/nicconf/review/58086670/6f59093ace">NICconf Opening and Keynote: Modernizing Windows Server/Modernizing Ourselves &#8211; by Jeffrey Snover</a>
<li><a href="http://vimeo.com/58361161">Jeffrey Snover: PowerShell CrashCourse</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.powershell.no/2013/02/06/videos-from-nordic-infrastructure-conference-2013/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>2013 Microsoft MVP Award</title>
		<link>http://blog.powershell.no/2013/01/03/2013-microsoft-mvp-award/</link>
		<comments>http://blog.powershell.no/2013/01/03/2013-microsoft-mvp-award/#comments</comments>
		<pubDate>Thu, 03 Jan 2013 19:19:43 +0000</pubDate>
		<dc:creator>Jan Egil Ring</dc:creator>
				<category><![CDATA[Windows PowerShell]]></category>
		<category><![CDATA[Jan Egil Ring]]></category>
		<category><![CDATA[MVP]]></category>

		<guid isPermaLink="false">http://blog.powershell.no/?p=14551</guid>
		<description><![CDATA[On January 1st I got an e-mail from Microsoft stating that I am renewed as a PowerShell MVP for another year: Dear Jan Egil Ring,Congratulations! We are pleased to present you with the 2013 Microsoft® MVP Award! This award is &#8230; <a href="http://blog.powershell.no/2013/01/03/2013-microsoft-mvp-award/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>On January 1st I got an e-mail from Microsoft stating that I am renewed as a PowerShell MVP for another year:</p>
<blockquote><p>Dear Jan Egil Ring,<br />Congratulations! We are pleased to present you with the 2013 Microsoft® MVP Award! This award is given to exceptional technical community leaders who actively share their high quality, real world expertise with others. We appreciate your outstanding contributions in PowerShell technical communities during the past year.</p>
</blockquote>
<p>This is the 3rd time I receive this award, and I am very honored and privileged to be part of this amazing community. Windows PowerShell 3.0 was released as part of Windows 8 and Windows Server 2012, with a very broad PowerShell coverage. I`m looking forward to contribute and interact with the PowerShell community in 2013, as we see that PowerShell is becoming more and more important.
<p><strong>Resources</strong>
<p><a href="http://mvp.microsoft.com/en-US/about-mvp/Pages/default.aspx">About the MVP Award Program</a>
<p><a href="http://mvp.microsoft.com/en-US/findanmvp/Pages/profile-results.aspx?tx=PowerShell&amp;ty=a&amp;so=n&amp;pa=1">Windows PowerShell MVP Awardees</a>
<p><a href="http://mvp.microsoft.com/en-US/findanmvp/Pages/profile.aspx?MVPID=ee601fca-81c3-4299-9641-ab7d9335005b">Jan Egil Ring`s MVP Profile</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.powershell.no/2013/01/03/2013-microsoft-mvp-award/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Managing Windows Azure using Windows PowerShell</title>
		<link>http://blog.powershell.no/2012/11/11/managing-windows-azure-using-windows-powershell/</link>
		<comments>http://blog.powershell.no/2012/11/11/managing-windows-azure-using-windows-powershell/#comments</comments>
		<pubDate>Sun, 11 Nov 2012 11:45:56 +0000</pubDate>
		<dc:creator>Jan Egil Ring</dc:creator>
				<category><![CDATA[Windows Azure]]></category>
		<category><![CDATA[Windows PowerShell]]></category>
		<category><![CDATA[windows azure powershell]]></category>

		<guid isPermaLink="false">http://blog.powershell.no/?p=5361</guid>
		<description><![CDATA[Windows Azure is Microsoft`s platform for cloud computing, offering services such as databases, virtual machines and web sites. After being announced in 2008 and commercially available in 2010, the platform was primarily of interest for developers. In June 2012 Virtual &#8230; <a href="http://blog.powershell.no/2012/11/11/managing-windows-azure-using-windows-powershell/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Windows Azure is Microsoft`s platform for cloud computing, offering services such as databases, virtual machines and web sites. After being announced in 2008 and commercially available in 2010, the platform was primarily of interest for developers. In June 2012 Virtual Machines for Windows and Linux was announced, making the service more interesting for IT Professionals as well. </p>
<h1>Windows Azure Virtual Machines</h1>
<p>The first offering for running virtual machines in Windows Azure was the <a href="http://msdn.microsoft.com/en-us/library/windowsazure/gg433107.aspx">VM Role</a>, targeted at scale-out cloud services. This offering made it possible to upload your own Windows Server 2008 R2 VHD image, which could be managed using Remote Desktop. The main disadvantage with this service from an IT Professionals perspective is that the service uses non-persistent storage.</p>
<p>The new <a href="http://www.windowsazure.com/en-us/home/scenarios/virtual-machines/">Virtual Machines</a> offering, currently available in Preview, brings more features which makes it more attractive for IT Professionals. The main differences compared to the VM Role is persistent storage, and more networking features. This means you can configure your own networks as well as a VPN tunnel to your on-premises network in Windows Azure Virtual Machines. This makes the offering attractive for many scenarios, such as:</p>
<ul>
<li>Using Windows Azure as a secondary site
<li>Deploying services typically deployed in a traditional DMZ, such as scale-out web servers
<li>Lab and demo environments</li>
</ul>
<h1>Windows Azure PowerShell Cmdlets</h1>
<p>There are several API`s available to automate Windows Azure administration. Targeted mainly at developer there is a <a href="http://msdn.microsoft.com/en-us/library/windowsazure/ee460799.aspx">Windows Azure REST API</a>. For IT Professionals there are Windows Azure PowerShell Cmdlets available. The first PowerShell Cmdlets for managing Windows Azure was available on <a href="http://wappowershell.codeplex.com/">Codeplex</a>, while the currently available cmdlets is available directly from the engineering team. The cmdlets is available as a Windows PowerShell module, and requires Windows PowerShell 2.0 or 3.0. Features which can be managed from the module includes:</p>
<ul>
<li>Subscriptions
<li>Virtual Machines
<li>Virtual Networks
<li>Storage Accounts
<li>Cloud Services</li>
</ul>
<h2>Installation</h2>
<p>The steps to download, install and configure your computer for the Windows Azure PowerShell Cmdlets is well documented on the <a href="http://msdn.microsoft.com/en-us/library/windowsazure/jj554332.aspx">Get Started with Windows Azure Cmdlets</a> website.</p>
<p>The <a href="http://go.microsoft.com/?linkid=9811175&amp;clcid=0x409">download link</a> points directly to the Windows Azure PowerShell application available in the Web Platform Installer:</p>
<p><a href="http://blog.powershell.no/wp-content/uploads/2012/11/image.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blog.powershell.no/wp-content/uploads/2012/11/image_thumb.png" width="449" height="190"></a></p>
<p>The installer will add the path (C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\) to the Azure PowerShell module to the $env:PSModulePath environment variable, which means you can import the module using the module name:</p>
<div class="csharpcode">
<pre class="alt">Import-Module Azure</pre>
</div>
<p>If you are using Windows PowerShell 3.0, you can skip the manual module import, due to the new <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/dd878284(v=vs.85).aspx">module autoloading feature</a>.</p>
<p>If you have not enabled execution of PowerShell scripts on your computer, you would need to configure your PowerShell execution policy before importing the Azure PowerShell module. A general recommendation is to use RemoteSigned:</p>
<div class="csharpcode">
<pre class="alt">Set-ExecutionPolicy RemoteSigned</pre>
</div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<p>To explore the available cmdlets, we can use Get-Command:</p>
<div class="csharpcode">
<pre class="alt">Get-Command -Module azure</pre>
</div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<p>There is also an overview of the currently available cmdlets on the <a href="http://msdn.microsoft.com/en-us/library/windowsazure/jj152841.aspx">Windows Azure Management Cmdlets</a> website.</p>
<h2>Configuration</h2>
<p>Before you can use any of the cmdlets to manage your Azure subscription, you must configure the publish settings and subscription information for your Windows Azure subscription. There are two ways to accomplish this:</p>
<ol>
<li>Automated configuration using Get-AzurePublishSettingsFile and Import-AzurePublishSettingsFile
<li>Manual configuration using Set-AzureSubscription and Select-AzureSubscription</li>
</ol>
<p>#1 is the easiest one, you first run Get-AzurePublishSettingsFile which opens your default web browser where you have to sign-in to Windows Azure in order to download your settings file. When you have downloaded the file you use Import-AzurePublishSettingsFile and specify the path to the .publishsettings file you downloaded.</p>
<p>#2 requires more work, but is appropriate if you want more control over the settings. For example you may want to use your own certificate which you have uploaded to the <a href="https://manage.windowsazure.com/#Workspace/AdminTasks/ListManagementCertificates">Windows Azure Management Certificates</a> store. This is a sample on how to use Set-AzureSubscription:</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span> Set-AzureSubscription `</pre>
<pre><span class="lnum">   2:  </span>     -SubscriptionId   26e6d24e-7e46-4a30-9f58-a14706bbfea1 `</pre>
<pre class="alt"><span class="lnum">   3:  </span>     -Certificate      (Get-ChildItem cert:\currentuser\my\8A15ED234D550ECBEDB7E051C59820105BFC2BEC) `</pre>
<pre><span class="lnum">   4:  </span>     -SubscriptionName <span class="str">"Windows Azure MSDN – Visual Studio Ultimate"</span></pre>
</div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<p>Now you should be able to use Get-AzureSubscription to see the details of the subscription you have configured. If you have configured more than one subscription, you can switch between the subscriptions using Select-AzureSubscription.</p>
<p>One last thing you might want to configure is a default storage account. Several cmdlets requires you to specify a storage account, which you will not need to do if you have configured a default account. To list the available storage accounts, run Get-AzureStorageAccount. To configure a default account, use Set-AzureSubscription with the CurrentStorageAccount parameter. An example:</p>
<div class="csharpcode">
<pre class="alt">Get-AzureSubscription | Set-AzureSubscription -CurrentStorageAccount portalvhdspd3kt2t</pre>
</div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<h2>&nbsp;</h2>
<h2>Usage</h2>
<p>Now that you have installed and configured your environment for Windows Azure PowerShell cmdlets, you are ready to use them.</p>
<p>I would recommend you to start exploring what is available by using the Get- cmdlets. You can obtain all of the Azure Get- cmdlets by using Get-Command:</p>
<div class="csharpcode">
<pre class="alt">Get-Command -Module azure -Verb Get</pre>
</div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<p>&nbsp;</p>
<p>For example, start with the Get-AzureVMImage cmdlet to obtain information about the available virtual machine images:</p>
<p><a href="http://blog.powershell.no/wp-content/uploads/2012/11/image1.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blog.powershell.no/wp-content/uploads/2012/11/image_thumb1.png" width="644" height="179"></a></p>
<p>Get-AzureVM will list your virtual machines:</p>
<p><a href="http://blog.powershell.no/wp-content/uploads/2012/11/image2.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blog.powershell.no/wp-content/uploads/2012/11/image_thumb2.png" width="644" height="122"></a></p>
<p>Start a virtual machine:</p>
<p><a href="http://blog.powershell.no/wp-content/uploads/2012/11/image3.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://blog.powershell.no/wp-content/uploads/2012/11/image_thumb3.png" width="644" height="84"></a></p>
<p>A few examples of typical usage:</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span><span class="rem"># Create a new virtual machine</span></pre>
<pre><span class="lnum">   2:  </span>New-AzureVMConfig -Name <span class="str">"DEMO-01"</span> -InstanceSize ExtraSmall -ImageName (Get-AzureVMImage)[3].ImageName `</pre>
<pre class="alt"><span class="lnum">   3:  </span>              | Add-AzureProvisioningConfig –Windows –Password <span class="str">"P@ssw0rd"</span> `</pre>
<pre><span class="lnum">   4:  </span>              | New-AzureVM –ServiceName <span class="str">"DEMO-01"</span> -Location <span class="str">"West Europe"</span> -VNetName <span class="str">"Azure Vnet 01"</span> -AffinityGroup 1</pre>
<pre class="alt"><span class="lnum">   5:  </span>&nbsp;</pre>
<pre><span class="lnum">   6:  </span><span class="rem"># Start the new virtual machine</span></pre>
<pre class="alt"><span class="lnum">   7:  </span>Get-AzureVM <span class="str">"DEMO-01"</span> | Start-AzureVM</pre>
<pre><span class="lnum">   8:  </span>&nbsp;</pre>
<pre class="alt"><span class="lnum">   9:  </span><span class="rem"># Connect to the new virtual machine using Remote Desktop</span></pre>
<pre><span class="lnum">  10:  </span>Get-AzureRemoteDesktopFile -ServiceName <span class="str">"DEMO-01"</span> -Name <span class="str">"DEMO-01"</span> –Launch</pre>
<pre class="alt"><span class="lnum">  11:  </span>&nbsp;</pre>
<pre><span class="lnum">  12:  </span><span class="rem"># Save your virtual network configuration to an XML-file</span></pre>
<pre class="alt"><span class="lnum">  13:  </span>Get-AzureVNetConfig | Select-Object -Expand XMLConfiguration | Out-File c:\temp\Azure-Vnet.xml</pre>
</div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<p>When you create a new virtual machine, by default an endpoint for Remote Desktop will be created. If you do not want this default endpoint to be created, you can specify the switch parameter –NoRDPEndpoint on the Add-AzureProvisioningConfig cmdlet.</p>
<p>You can also create your own endpoints, for example for PowerShell Remoting (TCP 5985):</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span><span class="rem"># Add an endpoint for PowerShell Remoting (Windows Remote Management)</span></pre>
<pre><span class="lnum">   2:  </span>Get-AzureVM <span class="str">"DC-AZURE-01"</span> | Add-AzureEndpoint -Name <span class="str">"WinRM"</span> -PublicPort 5985 -LocalPort 5985 -Protocol tcp | Update-AzureVM</pre>
<pre class="alt"><span class="lnum">   3:  </span>&nbsp;</pre>
<pre><span class="lnum">   4:  </span><span class="rem"># Add the hostname of the virtual machine to the local WSMan Trusted Hosts</span></pre>
<pre class="alt"><span class="lnum">   5:  </span>Set-Item WSMan:\localhost\Client\TrustedHosts -Value <span class="str">"demo-01.cloudapp.net"</span></pre>
<pre><span class="lnum">   6:  </span>&nbsp;</pre>
<pre class="alt"><span class="lnum">   7:  </span><span class="rem"># Connect to the virtual machine using PowerShell Remoting</span></pre>
<pre><span class="lnum">   8:  </span>Enter-PSSession -ComputerName demo-01.cloudapp.net -Credential (Get-Credential)</pre>
</div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
<p>&nbsp;</p>
<p>You can find more information on how to use the cmdlets on the&nbsp; <a href="http://msdn.microsoft.com/en-us/library/windowsazure/jj835083.aspx">Use Windows Azure Cmdlets</a> website.</p>
<p>I would also recommend you to download the Windows Azure Training Kit, which contains demos, labs and presentations. I would like to highlight the following presentations:</p>
<ul>
<li>WindowsAzureITProOverview.pptx</li>
<li>WindowsAzureVirtualMachines.pptx</li>
<li>ManagingVMs-PowerShell.pptx</li>
</ul>
<p>There are also several PowerShell related labs in the training kit, for example <em>Automating VM Management with PowerShell</em>, and <em>Deploying Active Directory with PowerShell</em>.</p>
<h1>Resources</h1>
<p><a href="http://www.windowsazure.com/en-us/manage/windows/">Windows Azure Virtual Machines</a></p>
<p><a href="http://msdn.microsoft.com/en-us/library/windowsazure/jj156055.aspx">Windows Azure PowerShell</a></p>
<p><a href="https://manage.windowsazure.com/">Windows Azure Management Portal</a></p>
<p><a href="http://www.microsoft.com/en-us/download/details.aspx?id=8396">Windows Azure Training Kit</a></p>
<p><a href="http://www.windowsazure.com/en-us/pricing/free-trial/">Sign up for a Windows Azure 90 day free trial</a></p>
<p>Trivia: This WordPress blog is hosted on <a href="http://www.windowsazure.com/en-us/home/scenarios/web-sites/">Windows Azure Web Sites.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.powershell.no/2012/11/11/managing-windows-azure-using-windows-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
