<?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>Jonathan Medd&#039;s Blog &#187; cmdlet series</title>
	<atom:link href="http://www.jonathanmedd.net/category/cmdlet-series/feed" rel="self" type="application/rss+xml" />
	<link>http://www.jonathanmedd.net</link>
	<description>Scripting. Powershell, VMware, Windows, Active Directory &#38; Exchange. All that kind of stuff.....</description>
	<lastBuildDate>Wed, 21 Jul 2010 12:41:22 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PowerShell 2.0: One Cmdlet at a Time #107 Add-Type</title>
		<link>http://www.jonathanmedd.net/2010/06/powershell-2-0-one-cmdlet-at-a-time-107-add-type.html</link>
		<comments>http://www.jonathanmedd.net/2010/06/powershell-2-0-one-cmdlet-at-a-time-107-add-type.html#comments</comments>
		<pubDate>Wed, 30 Jun 2010 13:27:02 +0000</pubDate>
		<dc:creator>Jonathan Medd</dc:creator>
				<category><![CDATA[cmdlet series]]></category>
		<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://www.jonathanmedd.net/?p=1291</guid>
		<description><![CDATA[Continuing the series looking at new cmdlets available in PowerShell                              2.0. This time we look at the Add-Type cmdlet.
What can I do with it?
Imbed code from [...]]]></description>
			<content:encoded><![CDATA[<p>Continuing the series looking at new cmdlets available in <a href="http://support.microsoft.com/kb/968929" target="_blank">PowerShell                              2.0</a>. This time we look at the <a href="http://go.microsoft.com/fwlink/?LinkID=135195" target="_blank">Add-Type</a> cmdlet.</p>
<p><strong>What can I do with it?</strong></p>
<p>Imbed code from modern programming languages into your PowerShell session or scripts. The list of valid languages are: C#, C# 3.0, VisualBasic and JScript &#8211; C# is the default. Use the <strong>Language</strong> parameter to specify one if it is not C#.</p>
<p><a rel="attachment wp-att-1296" href="http://www.jonathanmedd.net/2010/06/powershell-2-0-one-cmdlet-at-a-time-107-add-type.html/add-type1-2"><img class="aligncenter size-full wp-image-1296" title="Add-Type1" src="http://www.jonathanmedd.net/wp-content/uploads/2010/06/Add-Type11.JPG" alt="Add-Type1" width="567" height="50" /></a></p>
<p><strong>Example:</strong></p>
<p>Within a PowerShell session use some C# code to create a <strong>TakeAway</strong> class and create a static method <strong>Minus</strong>. Use the Add-Type cmdlet to add the class to the session and then call the <strong>TakeAway</strong> class and <strong>Minus</strong> static method.</p>
<pre><span style="color: #800080;">$csharp</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">@"
</span><span style="color: #800000;">public class TakeAway
{
    public static int Minus(int a, int b)
    {
        return (a - b);
    }
}
</span><span style="color: #800000;">"@</span><span style="color: #000000;">
</span><span style="color: #5F9EA0; font-weight: bold;">Add-Type</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-TypeDefinition</span><span style="color: #000000;"> </span><span style="color: #800080;">$csharp</span><span style="color: #000000;">
[TakeAway]::Minus(</span><span style="color: #000000;">10</span><span style="color: #000000;">,</span><span style="color: #000000;">7</span><span style="color: #000000;">)</span></pre>
<p>You will see that we get the expected answer of 3:</p>
<p><a rel="attachment wp-att-1297" href="http://www.jonathanmedd.net/2010/06/powershell-2-0-one-cmdlet-at-a-time-107-add-type.html/add-type2"><img class="aligncenter size-full wp-image-1297" title="Add-Type2" src="http://www.jonathanmedd.net/wp-content/uploads/2010/06/Add-Type2.JPG" alt="Add-Type2" width="366" height="223" /></a></p>
<p><strong>How could I have done this in PowerShell 1.0?</strong></p>
<p>PowerShell 1.0 did not support adding C# or other code into PowerShell scripts, you could however have created your own cmdlet which I&#8217;m sure would have been very straightforward for most sysadmins <img src='http://www.jonathanmedd.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> <span style="color: #000000;"><br />
</span></p>
<p><a href="http://blogs.msdn.com/powershell/archive/2008/09/19/a-thousand-things-1-better.aspx" target="_blank">1000 things 1% better!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonathanmedd.net/2010/06/powershell-2-0-one-cmdlet-at-a-time-107-add-type.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell 2.0: One Cmdlet at a Time #106 Import-LocalizedData</title>
		<link>http://www.jonathanmedd.net/2010/06/powershell-2-0-one-cmdlet-at-a-time-106-import-localizeddata.html</link>
		<comments>http://www.jonathanmedd.net/2010/06/powershell-2-0-one-cmdlet-at-a-time-106-import-localizeddata.html#comments</comments>
		<pubDate>Mon, 28 Jun 2010 13:16:51 +0000</pubDate>
		<dc:creator>Jonathan Medd</dc:creator>
				<category><![CDATA[cmdlet series]]></category>
		<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://www.jonathanmedd.net/?p=1284</guid>
		<description><![CDATA[Continuing the series looking at new cmdlets available in PowerShell                             2.0. This time we look at the Import-LocalizedData cmdlet.
What can I do with it?
Enable text in scripts [...]]]></description>
			<content:encoded><![CDATA[<p>Continuing the series looking at new cmdlets available in <a href="http://support.microsoft.com/kb/968929" target="_blank">PowerShell                             2.0</a>. This time we look at the <a href="http://go.microsoft.com/fwlink/?LinkID=113342" target="_blank">Import-LocalizedData</a> cmdlet.</p>
<p><strong>What can I do with it?</strong></p>
<p>Enable text in scripts displayed to users to be presented in their own language. The cmdlet uses the automatic variable <strong>$PSUICulture</strong> to determine the language to use and alternate text is stored within .psd1 files in subdirectories of the folder that the script is stored.</p>
<p><strong>Example:</strong></p>
<p>In a script called <strong>RegionalTest.ps1</strong> use the <a href="http://www.jonathanmedd.net/2010/03/powershell-2-0-one-cmdlet-at-a-time-85-convertfrom-stringdata.html" target="_blank">ConvertFrom-StringData</a> cmdlet to create a series of text messages to display to the user. Import-LocalizedData will retrieve the value of the <strong>$PSUICulture</strong> automatic variable, get the contents of the <strong>RegionalTest.psd1</strong> file in the <strong>es-ES</strong> directory (assume the user is Spanish) and store the data within the variable designated by the <strong>BindingVariable</strong> parameter. Then display the Welcome text.</p>
<pre><span style="color: #800080;">$UserMessages</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> Data {
    </span><span style="color: #008000;">#</span><span style="color: #008000;"> culture="en-US"</span><span style="color: #008000;">
</span><span style="color: #000000;">    </span><span style="color: #5F9EA0; font-weight: bold;">ConvertFrom-StringData</span><span style="color: #000000;"> </span><span style="color: #800000;">@'
</span><span style="color: #800000;">    Welcome = Welcome to the application
    Error1 = You have entered an incorrect username
    Error2 = You have entered an incorrect password
</span><span style="color: #800000;">'@</span><span style="color: #000000;">
    }

</span><span style="color: #5F9EA0; font-weight: bold;">Import-LocalizedData</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-BindingVariable</span><span style="color: #000000;"> </span><span style="color: #800080;">$UserMessages</span><span style="color: #000000;">

</span><span style="color: #800080;">$UserMessages</span><span style="color: #000000;">.Welcome</span></pre>
<p>The contents of the RegionalTest.psd1 file for Spanish would look like (apologies for any bad translation!)</p>
<pre><span style="color: #5F9EA0; font-weight: bold;">ConvertFrom-StringData</span><span style="color: #000000;"> </span><span style="color: #800000;">@'
</span><span style="color: #800000;">    Welcome = Recepción al uso
    Error1 = Usted ha incorporado un username incorrecto
    Error2 = Usted ha incorporado una contraseña incorrecta
</span><span style="color: #800000;">'@</span></pre>
<p>and be stored in the es-ES folder below C:\Scripts where RegionalTest.ps1 lives</p>
<p><a rel="attachment wp-att-1287" href="http://www.jonathanmedd.net/2010/06/powershell-2-0-one-cmdlet-at-a-time-106-import-localizeddata.html/import-localizeddata-3"><img class="aligncenter size-full wp-image-1287" title="Import-LocalizedData" src="http://www.jonathanmedd.net/wp-content/uploads/2010/06/Import-LocalizedData2.png" alt="Import-LocalizedData" width="482" height="203" /></a></p>
<p>When run on the Spanish user&#8217;s machine the Spanish text would be displayed rather than the original English.</p>
<p><strong>How could I have done this in PowerShell 1.0?</strong></p>
<p>Script Internationalisation features were introduced in PowerShell 2.0 and not s<span style="color: #000000;">upported in version 1.0 &#8211; <a href="http://technet.microsoft.com/en-us/library/dd315390.aspx" target="_blank">more info here</a>.<br />
</span></p>
<p><a href="http://blogs.msdn.com/powershell/archive/2008/09/19/a-thousand-things-1-better.aspx" target="_blank">1000 things 1% better!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonathanmedd.net/2010/06/powershell-2-0-one-cmdlet-at-a-time-106-import-localizeddata.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell 2.0: One Cmdlet at a Time #105 Set-StrictMode</title>
		<link>http://www.jonathanmedd.net/2010/06/powershell-2-0-one-cmdlet-at-a-time-105-set-strictmode.html</link>
		<comments>http://www.jonathanmedd.net/2010/06/powershell-2-0-one-cmdlet-at-a-time-105-set-strictmode.html#comments</comments>
		<pubDate>Fri, 18 Jun 2010 13:07:28 +0000</pubDate>
		<dc:creator>Jonathan Medd</dc:creator>
				<category><![CDATA[cmdlet series]]></category>
		<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://www.jonathanmedd.net/?p=1262</guid>
		<description><![CDATA[Continuing the series looking at new cmdlets available in PowerShell                             2.0. This time we look at the Set-StrictMode cmdlet.
What can I do with it?
Configure strict mode for [...]]]></description>
			<content:encoded><![CDATA[<p>Continuing the series looking at new cmdlets available in <a href="http://support.microsoft.com/kb/968929" target="_blank">PowerShell                             2.0</a>. This time we look at the <a href="http://go.microsoft.com/fwlink/?LinkID=113450" target="_blank">Set-StrictMode</a> cmdlet.</p>
<p><strong>What can I do with it?</strong></p>
<p>Configure strict mode for the current scope. An error will be generated when the content of an expression, script or script block violates coding rules. Note: it is possible to use the <strong>Version</strong> parameter to pick which coding rules to use. The <a href="http://go.microsoft.com/fwlink/?LinkID=113450" target="_blank">PowerShell help</a> lists the current possible options as:</p>
<p><strong>1.0</strong></p>
<p>&#8211; Prohibits references to uninitialized variables, except for  uninitialized variables in strings.</p>
<p><strong>2.0</strong></p>
<p>&#8211; Prohibits references to uninitialized variables (including  uninitialized variables in strings).</p>
<p>&#8211; Prohibits references to non-existent properties of an  object.</p>
<p>&#8211; Prohibits function calls that use the syntax for calling  methods.</p>
<p>&#8211; Prohibits a variable without a name (${}).</p>
<p><strong>Latest</strong></p>
<p>&#8211;Selects the latest (most strict) version available.  Use this value to  assure that scripts use the strictest available version, even when new  versions are added to Windows PowerShell.</p>
<p><strong>Example:</strong></p>
<p>Examine what happens when you add the undefined $b to the undefined $a with strict mode off. Next, turn on strict mode using Version 1.0 and run the same test.</p>
<pre><span style="color: #800080;">$a</span><span style="color: #000000;"> </span><span style="color: #FF0000;">+</span><span style="color: #000000;"> </span><span style="color: #800080;">$b</span><span style="color: #000000;">
</span><span style="color: #5F9EA0; font-weight: bold;">Set-StrictMode</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-Version</span><span style="color: #000000;"> </span><span style="color: #800000;">1.0</span><span style="color: #000000;">
</span><span style="color: #800080;">$a</span><span style="color: #000000;"> </span><span style="color: #FF0000;">+</span><span style="color: #000000;"> </span><span style="color: #800080;">$b</span></pre>
<p>Note the error message generated with strict mode on because $a has not been initialised.</p>
<p><a rel="attachment wp-att-1263" href="http://www.jonathanmedd.net/2010/06/powershell-2-0-one-cmdlet-at-a-time-105-set-strictmode.html/set-strictmode1"><img class="aligncenter size-full wp-image-1263" title="Set-StrictMode1" src="http://www.jonathanmedd.net/wp-content/uploads/2010/06/Set-StrictMode1.png" alt="Set-StrictMode1" width="491" height="118" /></a></p>
<p>Examine what happens when you define $a to be a numerical value and attempt to reference a property  with strict mode off. Next, turn on strict mode using Version 2.0 and  run the same test.</p>
<pre><span style="color: #800080;">$a</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #000000;">32</span><span style="color: #000000;">
</span><span style="color: #800080;">$a</span><span style="color: #000000;">.Time
</span><span style="color: #5F9EA0; font-weight: bold;">Set-StrictMode</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-Version</span><span style="color: #000000;"> </span><span style="color: #800000;">2.0</span><span style="color: #000000;">
</span><span style="color: #800080;">$a</span><span style="color: #000000;">.Time</span></pre>
<p>Note the error message generated with strict mode on because the Time property does not exist.</p>
<p><a rel="attachment wp-att-1264" href="http://www.jonathanmedd.net/2010/06/powershell-2-0-one-cmdlet-at-a-time-105-set-strictmode.html/set-strictmode2"><img class="aligncenter size-full wp-image-1264" title="Set-StrictMode2" src="http://www.jonathanmedd.net/wp-content/uploads/2010/06/Set-StrictMode2.png" alt="Set-StrictMode2" width="533" height="122" /></a></p>
<p><strong>How could I have done this in PowerShell 1.0?</strong></p>
<p>You could have used <a href="http://technet.microsoft.com/en-us/library/dd315302.aspx" target="_blank">Set-PSDebug</a>, however Set-Strictmode applies only to the current scope or child scopes and does not impact the global scope. For more information on scopes in PowerShell <a href="http://technet.microsoft.com/en-us/library/dd315289.aspx" target="_blank">look here</a>.</p>
<p><a href="http://blogs.msdn.com/powershell/archive/2008/09/19/a-thousand-things-1-better.aspx" target="_blank">1000 things 1% better!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonathanmedd.net/2010/06/powershell-2-0-one-cmdlet-at-a-time-105-set-strictmode.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell 2.0: One Cmdlet at a Time #104 Trace-Command</title>
		<link>http://www.jonathanmedd.net/2010/06/powershell-2-0-one-cmdlet-at-a-time-104-trace-command.html</link>
		<comments>http://www.jonathanmedd.net/2010/06/powershell-2-0-one-cmdlet-at-a-time-104-trace-command.html#comments</comments>
		<pubDate>Thu, 17 Jun 2010 12:58:34 +0000</pubDate>
		<dc:creator>Jonathan Medd</dc:creator>
				<category><![CDATA[cmdlet series]]></category>
		<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://www.jonathanmedd.net/?p=1247</guid>
		<description><![CDATA[Continuing the series looking at new cmdlets available in PowerShell                            2.0. This time we look at the Trace-Command cmdlet.
What can I do with it?
Begin a trace of a [...]]]></description>
			<content:encoded><![CDATA[<p>Continuing the series looking at new cmdlets available in <a href="http://support.microsoft.com/kb/968929" target="_blank">PowerShell                            2.0</a>. This time we look at the <a href="http://go.microsoft.com/fwlink/?LinkID=113419" target="_blank">Trace-Command</a> cmdlet.</p>
<p><strong>What can I do with it?</strong></p>
<p>Begin a trace of a command or expression.</p>
<p><strong>Example:</strong></p>
<p>Examine debug info for Parameter Binding when piping a string through to Get-Service.</p>
<pre><span style="color: #5F9EA0; font-weight: bold;">Trace-Command</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-Name</span><span style="color: #000000;"> </span><span style="color: #800000;">ParameterBinding</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-Option</span><span style="color: #000000;"> </span><span style="color: #800000;">All</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-Expression</span><span style="color: #000000;"> {</span><span style="color: #800000;">'</span><span style="color: #800000;">winmgmt</span><span style="color: #800000;">'</span><span style="color: #000000;"> | </span><span style="color: #5F9EA0; font-weight: bold;">Get-Service</span><span style="color: #000000;">} </span><span style="color: #5F9EA0; font-style: italic;">-PSHost</span></pre>
<p>You will see it is possible to work through the debug info to find out what is happening:</p>
<p><a rel="attachment wp-att-1248" href="http://www.jonathanmedd.net/2010/06/powershell-2-0-one-cmdlet-at-a-time-104-trace-command.html/trace-command"><img class="aligncenter size-full wp-image-1248" title="Trace-Command" src="http://www.jonathanmedd.net/wp-content/uploads/2010/06/Trace-Command.png" alt="Trace-Command" width="574" height="259" /></a></p>
<p>Note: it is also possible to output the debug info to a file, simply remove the <strong>PSHost</strong> parameter and use <strong>FilePath</strong> instead.</p>
<pre><span style="color: #5F9EA0; font-weight: bold;">Trace-Command</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-Name</span><span style="color: #000000;"> </span><span style="color: #800000;">ParameterBinding</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-Option</span><span style="color: #000000;"> </span><span style="color: #800000;">All</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-Expression</span><span style="color: #000000;"> {</span><span style="color: #800000;">'</span><span style="color: #800000;">winmgmt</span><span style="color: #800000;">'</span><span style="color: #000000;"> | </span><span style="color: #5F9EA0; font-weight: bold;">Get-Service</span><span style="color: #000000;">} </span><span style="color: #5F9EA0; font-style: italic;">-FilePath</span><span style="color: #000000;"> </span><span style="color: #800000;">C:\Debug.txt</span></pre>
<p>The resulting debug info is now easily viewable in Notepad.</p>
<p><a rel="attachment wp-att-1257" href="http://www.jonathanmedd.net/2010/06/powershell-2-0-one-cmdlet-at-a-time-104-trace-command.html/trace-command2-2"><img class="aligncenter size-full wp-image-1257" title="Trace-Command2" src="http://www.jonathanmedd.net/wp-content/uploads/2010/06/Trace-Command21.png" alt="Trace-Command2" width="597" height="199" /></a></p>
<p><strong>How could I have done this in PowerShell 1.0?</strong></p>
<p>You could have used <a href="http://technet.microsoft.com/en-us/library/dd315364.aspx" target="_blank">Set-TraceSource</a> , but Trace-Command applies the trace only to the specified command.</p>
<p><a href="http://blogs.msdn.com/powershell/archive/2008/09/19/a-thousand-things-1-better.aspx" target="_blank">1000 things 1% better!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonathanmedd.net/2010/06/powershell-2-0-one-cmdlet-at-a-time-104-trace-command.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell 2.0: One Cmdlet at a Time #103 Update-List</title>
		<link>http://www.jonathanmedd.net/2010/06/powershell-2-0-one-cmdlet-at-a-time-103-update-list.html</link>
		<comments>http://www.jonathanmedd.net/2010/06/powershell-2-0-one-cmdlet-at-a-time-103-update-list.html#comments</comments>
		<pubDate>Thu, 17 Jun 2010 11:58:09 +0000</pubDate>
		<dc:creator>Jonathan Medd</dc:creator>
				<category><![CDATA[cmdlet series]]></category>
		<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://www.jonathanmedd.net/?p=1244</guid>
		<description><![CDATA[Continuing the series looking at new cmdlets available in PowerShell                           2.0. This time we look at the Update-List cmdlet.
What can I do with it?
Add, Remove or Replace items from [...]]]></description>
			<content:encoded><![CDATA[<p>Continuing the series looking at new cmdlets available in <a href="http://support.microsoft.com/kb/968929" target="_blank">PowerShell                           2.0</a>. This time we look at the <a href="http://go.microsoft.com/fwlink/?LinkID=113447" target="_blank">Update-List</a> cmdlet.</p>
<p><strong>What can I do with it?</strong></p>
<p>Add, Remove or Replace items from a property value of an object. This cmdlet can only update a property when it supports the <a href="http://msdn.microsoft.com/en-us/library/system.collections.ilist.aspx" target="_blank">IList interface</a>. So far this does not include any of the core Windows PowerShell cmdlets &#8211; however it does include some of the cmdlets that ship with Exchange 2007 and later.</p>
<p><strong>Example:</strong></p>
<p>Add additional email addresses to the Test1 user&#8217;s mailbox using the <strong>Add</strong> parameter of Update-List.</p>
<pre><span style="color: #000000;">Get-Mailbox Test1  | </span><span style="color: #5F9EA0; font-weight: bold;">Update-List</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-Property</span><span style="color: #000000;"> </span><span style="color: #800000;">EmailAddresses</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-Add</span><span style="color: #000000;"> admin@</span><span style="color: #800000;">contoso.com</span><span style="color: #000000;">,webmaster@</span><span style="color: #800000;">contoso.com</span><span style="color: #000000;">
| Set-Mailbox</span></pre>
<p><strong>How could I have done this in PowerShell 1.0?</strong></p>
<p>Shay Levy has a great <a href="http://blogs.microsoft.co.il/blogs/scriptfanatic/archive/2010/02/04/modifying-multivalued-active-directory-attributes.aspx" target="_blank">blog post</a> on dealing with AD / Mailbox accounts with multi-valued attributes.</p>
<p><a href="http://blogs.msdn.com/powershell/archive/2008/09/19/a-thousand-things-1-better.aspx" target="_blank">1000 things 1% better!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonathanmedd.net/2010/06/powershell-2-0-one-cmdlet-at-a-time-103-update-list.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell 2.0: One Cmdlet at a Time #102 Disable-PSRemoting</title>
		<link>http://www.jonathanmedd.net/2010/05/powershell-2-0-one-cmdlet-at-a-time-102-disable-psremoting.html</link>
		<comments>http://www.jonathanmedd.net/2010/05/powershell-2-0-one-cmdlet-at-a-time-102-disable-psremoting.html#comments</comments>
		<pubDate>Fri, 21 May 2010 12:29:13 +0000</pubDate>
		<dc:creator>Jonathan Medd</dc:creator>
				<category><![CDATA[cmdlet series]]></category>
		<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://www.jonathanmedd.net/?p=1237</guid>
		<description><![CDATA[Continuing the series looking at new cmdlets available in PowerShell                          2.0. This time we look at the Disable-PSRemoting function. Note: This is a proxy command which calls the Disable-PSSessionConfiguration cmdlet.
What [...]]]></description>
			<content:encoded><![CDATA[<p>Continuing the series looking at new cmdlets available in <a href="http://support.microsoft.com/kb/968929" target="_blank">PowerShell                          2.0</a>. This time we look at the <a href="http://go.microsoft.com/fwlink/?LinkID=144298" target="_blank">Disable-PSRemoting</a> function. Note: This is a proxy command which calls the <a href="http://www.jonathanmedd.net/2010/01/powershell-2-0-one-cmdlet-at-a-time-41-disable-pssessionconfiguration.html" target="_blank">Disable-PSSessionConfiguration</a> cmdlet.</p>
<p><strong>What can I do with it?</strong></p>
<p>Disable PowerShell remoting on a computer that has previously been enabled for remoting.<strong> Note:</strong> This command must be run from a PowerShell session with administrative privileges.</p>
<p><strong>Example:</strong></p>
<p>Retrieve the current PSSessionConfiguration settings. Disable PowerShell remoting, then retrieve the PSSessionConfiguration settings again to compare.</p>
<pre><span style="color: #5F9EA0; font-weight: bold;">Get-PSSessionConfiguration</span><span style="color: #000000;">
</span><span style="color: #5F9EA0;">Disable-PSRemoting</span><span style="color: #000000;">
</span><span style="color: #5F9EA0; font-weight: bold;">Get-PSSessionConfiguration</span></pre>
<p>Notice the PSSessionConfiguration on a machine enabled for PowerShell remoting</p>
<p><a rel="attachment wp-att-1238" href="http://www.jonathanmedd.net/2010/05/powershell-2-0-one-cmdlet-at-a-time-102-disable-psremoting.html/disable-psremoting1"><img class="aligncenter size-full wp-image-1238" title="Disable-PSRemoting1" src="http://www.jonathanmedd.net/wp-content/uploads/2010/05/Disable-PSRemoting1.png" alt="Disable-PSRemoting1" width="557" height="109" /></a></p>
<p>Disable PowerShell Remoting. You will receive the following warning that using this command does not necessarily reverse everythign that Enable-PSRemoting may have done.</p>
<p>WARNING: Disabling the session configurations does not undo all the changes made by the Enable-PSRemoting or<br />
Enable-PSSessionConfiguration cmdlet. You might have to manually undo the changes by following these steps.<br />
1. Stop and disable the WinRM service.<br />
2. Delete the listener that accepts requests on any IP address.<br />
3. Disable the firewall exceptions for WS-Management communications.<br />
4. Restore the value of the LocalAccountTokenFilterPolicy to 0, which restricts remote access to members of the<br />
Administrators group on the computer.</p>
<p><a rel="attachment wp-att-1239" href="http://www.jonathanmedd.net/2010/05/powershell-2-0-one-cmdlet-at-a-time-102-disable-psremoting.html/disable-psremoting2"><img class="aligncenter size-full wp-image-1239" title="Disable-PSRemoting2" src="http://www.jonathanmedd.net/wp-content/uploads/2010/05/Disable-PSRemoting2.png" alt="Disable-PSRemoting2" width="562" height="147" /></a></p>
<p>Now check the impact on the PSSessionconfiguration &#8211; the <strong>AccessDenied</strong> permission has been applied to <strong>Everyone</strong>.</p>
<p><a rel="attachment wp-att-1240" href="http://www.jonathanmedd.net/2010/05/powershell-2-0-one-cmdlet-at-a-time-102-disable-psremoting.html/disable-psremoting3"><img class="aligncenter size-full wp-image-1240" title="Disable-PSRemoting3" src="http://www.jonathanmedd.net/wp-content/uploads/2010/05/Disable-PSRemoting3.png" alt="Disable-PSRemoting3" width="578" height="106" /></a></p>
<p><strong>How could I have done this in PowerShell 1.0?</strong></p>
<p>Remoting did not exist in PowerShell 1.0, you would have needed to  use Remote Desktop to run an interactive session on a remote server.</p>
<p><a href="http://blogs.msdn.com/powershell/archive/2008/09/19/a-thousand-things-1-better.aspx" target="_blank">1000 things 1% better!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonathanmedd.net/2010/05/powershell-2-0-one-cmdlet-at-a-time-102-disable-psremoting.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell 2.0: One Cmdlet at a Time #101 Wait-Process</title>
		<link>http://www.jonathanmedd.net/2010/05/powershell-2-0-one-cmdlet-at-a-time-101-wait-process.html</link>
		<comments>http://www.jonathanmedd.net/2010/05/powershell-2-0-one-cmdlet-at-a-time-101-wait-process.html#comments</comments>
		<pubDate>Tue, 18 May 2010 15:59:36 +0000</pubDate>
		<dc:creator>Jonathan Medd</dc:creator>
				<category><![CDATA[cmdlet series]]></category>
		<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://www.jonathanmedd.net/?p=1229</guid>
		<description><![CDATA[Continuing the series looking at new cmdlets available in PowerShell                         2.0. This time we look at the Wait-Process cmdlet.
What can I do with it?
Wait for a process to stop before proceeding [...]]]></description>
			<content:encoded><![CDATA[<p>Continuing the series looking at new cmdlets available in <a href="http://support.microsoft.com/kb/968929" target="_blank">PowerShell                         2.0</a>. This time we look at the <a href="http://go.microsoft.com/fwlink/?LinkID=135277" target="_blank">Wait-Process</a> cmdlet.</p>
<p><strong>What can I do with it?</strong></p>
<p>Wait for a process to stop before proceeding further.</p>
<p><strong>Example:</strong></p>
<p>Open an instance of Notepad. Use Wait-Process to pause the console session until Notepad is closed.</p>
<pre><span style="color: #000000;">Notepad
</span><span style="color: #5F9EA0; font-weight: bold;">Wait-Process</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-Name</span><span style="color: #000000;"> </span><span style="color: #800000;">Notepad</span></pre>
<p>You will notice that the console pauses whilst Notepad is open</p>
<p><a rel="attachment wp-att-1230" href="http://www.jonathanmedd.net/2010/05/powershell-2-0-one-cmdlet-at-a-time-101-wait-process.html/wait-process1"><img class="aligncenter size-full wp-image-1230" title="Wait-Process1" src="http://www.jonathanmedd.net/wp-content/uploads/2010/05/Wait-Process1.png" alt="Wait-Process1" width="602" height="152" /></a></p>
<p>Once Notepad is closed, control of the session is returned to the user.</p>
<p><a rel="attachment wp-att-1231" href="http://www.jonathanmedd.net/2010/05/powershell-2-0-one-cmdlet-at-a-time-101-wait-process.html/wait-process2"><img class="aligncenter size-full wp-image-1231" title="Wait-Process2" src="http://www.jonathanmedd.net/wp-content/uploads/2010/05/Wait-Process2.png" alt="Wait-Process2" width="307" height="95" /></a></p>
<p><strong>How could I have done this in PowerShell 1.0?</strong></p>
<p>Store the result of Get-Process Notepad in a variable, then use the <strong>WaitForExit</strong> method to wait for the process to stop.</p>
<pre><span style="color: #000000;">Notepad
</span><span style="color: #800080;">$Process</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-weight: bold;">Get-Process</span><span style="color: #000000;"> </span><span style="color: #800000;">Notepad</span><span style="color: #000000;">
</span><span style="color: #800080;">$Process</span><span style="color: #000000;">.WaitForExit()</span></pre>
<p><a href="http://blogs.msdn.com/powershell/archive/2008/09/19/a-thousand-things-1-better.aspx" target="_blank">1000 things 1% better</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonathanmedd.net/2010/05/powershell-2-0-one-cmdlet-at-a-time-101-wait-process.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell 2.0: One Cmdlet at a Time #100 Remove-Event</title>
		<link>http://www.jonathanmedd.net/2010/05/powershell-2-0-one-cmdlet-at-a-time-100-remove-event.html</link>
		<comments>http://www.jonathanmedd.net/2010/05/powershell-2-0-one-cmdlet-at-a-time-100-remove-event.html#comments</comments>
		<pubDate>Thu, 13 May 2010 13:24:26 +0000</pubDate>
		<dc:creator>Jonathan Medd</dc:creator>
				<category><![CDATA[cmdlet series]]></category>
		<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://www.jonathanmedd.net/?p=1224</guid>
		<description><![CDATA[Continuing the series looking at new cmdlets available in PowerShell                        2.0. This time we look at the Remove-Event cmdlet.
What can I do with it?
Delete an event from the current session. Note: to [...]]]></description>
			<content:encoded><![CDATA[<p>Continuing the series looking at new cmdlets available in <a href="http://support.microsoft.com/kb/968929" target="_blank">PowerShell                        2.0</a>. This time we look at the <a href="http://go.microsoft.com/fwlink/?LinkID=135247" target="_blank">Remove-Event </a>cmdlet.</p>
<p><strong>What can I do with it?</strong></p>
<p>Delete an event from the current session. <strong>Note:</strong> to unsubscribe from an event you will need to use <a href="http://www.jonathanmedd.net/2010/05/powershell-2-0-one-cmdlet-at-a-time-99-unregister-event.html" target="_blank">Unregister-Event</a>.</p>
<p><strong>Example:</strong></p>
<p>Retrive current events in the queue with <a href="http://www.jonathanmedd.net/2010/05/powershell-2-0-one-cmdlet-at-a-time-97-get-event.html" target="_blank">Get-Event</a>, use Remove-Event to clear the event with the SourceIdentifier of <strong>Timer</strong>, then <a href="../2010/05/powershell-2-0-one-cmdlet-at-a-time-97-get-event.html" target="_blank">Get-Event</a> again to confirm that it has been removed.</p>
<pre><span style="color: #5F9EA0; font-weight: bold;">Get-Event</span><span style="color: #000000;">
</span><span style="color: #5F9EA0; font-weight: bold;">Remove-Event</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-SourceIdentifier</span><span style="color: #000000;"> </span><span style="color: #800000;">Timer</span><span style="color: #000000;">
</span><span style="color: #5F9EA0; font-weight: bold;">Get-Event</span></pre>
<p>You will see that the event has been cleared.</p>
<p><a rel="attachment wp-att-1225" href="http://www.jonathanmedd.net/2010/05/powershell-2-0-one-cmdlet-at-a-time-100-remove-event.html/remove-event"><img class="aligncenter size-full wp-image-1225" title="Remove-Event" src="http://www.jonathanmedd.net/wp-content/uploads/2010/05/Remove-Event.png" alt="Remove-Event" width="344" height="200" /></a></p>
<p><strong>How could I have done this in PowerShell 1.0?</strong></p>
<p>PowerShell engine events are a new feature in PowerShell 2.0.</p>
<p><a href="http://blogs.msdn.com/powershell/archive/2008/09/19/a-thousand-things-1-better.aspx" target="_blank">1000 things 1% better</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonathanmedd.net/2010/05/powershell-2-0-one-cmdlet-at-a-time-100-remove-event.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PowerShell 2.0: One Cmdlet at a Time #99 Unregister-Event</title>
		<link>http://www.jonathanmedd.net/2010/05/powershell-2-0-one-cmdlet-at-a-time-99-unregister-event.html</link>
		<comments>http://www.jonathanmedd.net/2010/05/powershell-2-0-one-cmdlet-at-a-time-99-unregister-event.html#comments</comments>
		<pubDate>Tue, 11 May 2010 11:44:01 +0000</pubDate>
		<dc:creator>Jonathan Medd</dc:creator>
				<category><![CDATA[cmdlet series]]></category>
		<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://www.jonathanmedd.net/?p=1220</guid>
		<description><![CDATA[Continuing the series looking at new cmdlets available in PowerShell                       2.0. This time we look at the Unregister-Event cmdlet.
What can I do with it?
Clear an event subscription.
Example:
Use Get-EventSubscriber to retrive details of current [...]]]></description>
			<content:encoded><![CDATA[<p>Continuing the series looking at new cmdlets available in <a href="http://support.microsoft.com/kb/968929" target="_blank">PowerShell                       2.0</a>. This time we look at the <a href="http://go.microsoft.com/fwlink/?LinkID=135269" target="_blank">Unregister-Event</a> cmdlet.</p>
<p><strong>What can I do with it?</strong></p>
<p>Clear an event subscription.</p>
<p><strong>Example:</strong></p>
<p>Use <a href="http://www.jonathanmedd.net/2010/04/powershell-2-0-one-cmdlet-at-a-time-94-get-eventsubscriber.html" target="_blank">Get-EventSubscriber</a> to retrive details of current events. Clear the event with subscription<strong> </strong>id <strong>1</strong> and <a href="../2010/04/powershell-2-0-one-cmdlet-at-a-time-94-get-eventsubscriber.html" target="_blank">Get-EventSubscriber</a> again to confirm that it has been removed.</p>
<pre><span style="color: #5F9EA0; font-weight: bold;">Get-EventSubscriber</span><span style="color: #000000;">
</span><span style="color: #5F9EA0; font-weight: bold;">Unregister-Event</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-SubscriptionId</span><span style="color: #000000;"> </span><span style="color: #000000;">1</span><span style="color: #000000;">
</span><span style="color: #5F9EA0; font-weight: bold;">Get-EventSubscriber</span></pre>
<p>You will see that the event subscription has been cleared.</p>
<p><a rel="attachment wp-att-1221" href="http://www.jonathanmedd.net/2010/05/powershell-2-0-one-cmdlet-at-a-time-99-unregister-event.html/unregister-event"><img class="aligncenter size-full wp-image-1221" title="Unregister-Event" src="http://www.jonathanmedd.net/wp-content/uploads/2010/05/Unregister-Event.png" alt="Unregister-Event" width="373" height="188" /></a></p>
<p><strong>How could I have done this in PowerShell 1.0?</strong></p>
<p>PowerShell engine events are a new feature in PowerShell 2.0.</p>
<p><a href="http://blogs.msdn.com/powershell/archive/2008/09/19/a-thousand-things-1-better.aspx" target="_blank">1000 things 1% better</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonathanmedd.net/2010/05/powershell-2-0-one-cmdlet-at-a-time-99-unregister-event.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell 2.0: One Cmdlet at a Time #98 Wait-Event</title>
		<link>http://www.jonathanmedd.net/2010/05/powershell-2-0-one-cmdlet-at-a-time-98-wait-event.html</link>
		<comments>http://www.jonathanmedd.net/2010/05/powershell-2-0-one-cmdlet-at-a-time-98-wait-event.html#comments</comments>
		<pubDate>Mon, 10 May 2010 12:15:21 +0000</pubDate>
		<dc:creator>Jonathan Medd</dc:creator>
				<category><![CDATA[cmdlet series]]></category>
		<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://www.jonathanmedd.net/?p=1214</guid>
		<description><![CDATA[Continuing the series looking at new cmdlets available in PowerShell                      2.0. This time we look at the Wait-Event cmdlet.
What can I do with it?
Pause a running script or session and wait for an event [...]]]></description>
			<content:encoded><![CDATA[<p>Continuing the series looking at new cmdlets available in <a href="http://support.microsoft.com/kb/968929" target="_blank">PowerShell                      2.0</a>. This time we look at the <a href="http://go.microsoft.com/fwlink/?LinkID=135276" target="_blank">Wait-Event</a> cmdlet.</p>
<p><strong>What can I do with it?</strong></p>
<p>Pause a running script or session and wait for an event to occur before continuing.</p>
<p><strong>Example:</strong></p>
<p>The built-in PowerShell help has a great example for <a href="../2010/05/powershell-2-0-one-cmdlet-at-a-time-96-new-event.html" target="_blank">New-Event</a>. It uses  <a href="../2010/05/powershell-2-0-one-cmdlet-at-a-time-96-new-event.html" target="_blank">New-Event</a> to create a custom event based on a  reaction to another event. Use Wait-Event to make the current session pause until a new process has been opened. Open Windows Calculator to make the event trigger and return the prompt to the user.</p>
<pre><span style="color: #0000FF;">function</span><span style="color: #000000;"> </span><span style="color: #5F9EA0;">Enable-ProcessCreationEvent</span><span style="color: #000000;">
{
   </span><span style="color: #800080;">$query</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-weight: bold;">New-Object</span><span style="color: #000000;"> </span><span style="color: #800000;">System.Management.WqlEventQuery</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">__InstanceCreationEvent</span><span style="color: #800000;">"</span><span style="color: #000000;">, (</span><span style="color: #5F9EA0; font-weight: bold;">New-Object</span><span style="color: #000000;"> </span><span style="color: #800000;">TimeSpan</span><span style="color: #000000;"> </span><span style="color: #000000;">0</span><span style="color: #000000;">,</span><span style="color: #000000;">0</span><span style="color: #000000;">,</span><span style="color: #000000;">1</span><span style="color: #000000;">), </span><span style="color: #800000;">"</span><span style="color: #800000;">TargetInstance isa 'Win32_Process'</span><span style="color: #800000;">"</span><span style="color: #000000;">
   </span><span style="color: #800080;">$processWatcher</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-weight: bold;">New-Object</span><span style="color: #000000;"> </span><span style="color: #800000;">System.Management.ManagementEventWatcher</span><span style="color: #000000;"> </span><span style="color: #800080;">$query</span><span style="color: #000000;">
   </span><span style="color: #800080;">$identifier</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">WMI.ProcessCreated</span><span style="color: #800000;">"</span><span style="color: #000000;">

   </span><span style="color: #5F9EA0; font-weight: bold;">Register-ObjectEvent</span><span style="color: #000000;"> </span><span style="color: #800080;">$processWatcher</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">EventArrived</span><span style="color: #800000;">"</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-SupportEvent</span><span style="color: #000000;"> </span><span style="color: #800080;">$identifier</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-Action</span><span style="color: #000000;"> {
       [</span><span style="color: #008080;">void</span><span style="color: #000000;">] (</span><span style="color: #5F9EA0; font-weight: bold;">New-Event</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-sourceID</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">PowerShell.ProcessCreated</span><span style="color: #800000;">"</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-Sender</span><span style="color: #000000;"> </span><span style="color: #800080;">$args</span><span style="color: #000000;">[0] </span><span style="color: #5F9EA0; font-style: italic;">-EventArguments</span><span style="color: #000000;"> </span><span style="color: #800080;">$args</span><span style="color: #000000;">[1].SourceEventArgs.NewEvent.TargetInstance)
   }
}
</span><span style="color: #5F9EA0; font-weight: bold;">Wait-Event</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-SourceIdentifier</span><span style="color: #000000;"> </span><span style="color: #800000;">PowerShell.ProcessCreated</span></pre>
<p>Before opening Windows Calculator:</p>
<p><a rel="attachment wp-att-1216" href="http://www.jonathanmedd.net/2010/05/powershell-2-0-one-cmdlet-at-a-time-98-wait-event.html/wait-event2"><img class="aligncenter size-full wp-image-1216" title="Wait-Event2" src="http://www.jonathanmedd.net/wp-content/uploads/2010/05/Wait-Event2.png" alt="Wait-Event2" width="385" height="69" /></a></p>
<p>You will notice that after the opening of Windows Calculator the event is triggered and the prompt is returned to the user.</p>
<p><a rel="attachment wp-att-1215" href="http://www.jonathanmedd.net/2010/05/powershell-2-0-one-cmdlet-at-a-time-98-wait-event.html/wait-event"><img class="aligncenter size-full wp-image-1215" title="Wait-Event" src="http://www.jonathanmedd.net/wp-content/uploads/2010/05/Wait-Event.png" alt="Wait-Event" width="463" height="196" /></a></p>
<p><strong>How could I have done this in PowerShell 1.0?</strong></p>
<p>PowerShell engine events are a new feature in PowerShell 2.0.</p>
<p><a href="http://blogs.msdn.com/powershell/archive/2008/09/19/a-thousand-things-1-better.aspx" target="_blank">1000 things 1% better</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonathanmedd.net/2010/05/powershell-2-0-one-cmdlet-at-a-time-98-wait-event.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
