<?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</title>
	<atom:link href="http://www.jonathanmedd.net/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>Fri, 05 Mar 2010 14:42:43 +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 #72 Export-ModuleMember</title>
		<link>http://www.jonathanmedd.net/2010/03/powershell-2-0-one-cmdlet-at-a-time-72-export-modulemember.html</link>
		<comments>http://www.jonathanmedd.net/2010/03/powershell-2-0-one-cmdlet-at-a-time-72-export-modulemember.html#comments</comments>
		<pubDate>Fri, 05 Mar 2010 14:22:16 +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=973</guid>
		<description><![CDATA[Continuing the series looking at new cmdlets available in PowerShell         2.0. This time we look at the Export-ModuleMember cmdlet.
What can I do with it?
PowerShell 2.0 introduces the concept of modules; essentially they   are  the evolution of snapins from PowerShell 1.0. Export-ModuleMember specifies elements 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=141551" target="_blank">Export-ModuleMember</a> cmdlet.</p>
<p><strong>What can I do with it?</strong></p>
<p>PowerShell 2.0 introduces the concept of modules; essentially they   are  the evolution of snapins from PowerShell 1.0. Export-ModuleMember specifies elements from a module, like functions or variables, which can be exported. <strong>Note</strong>: This cmdlet can only be used within a *.psm1 script module file or a dynamic module created with <a href="http://www.jonathanmedd.net/2010/03/powershell-2-0-one-cmdlet-at-a-time-71-new-module.html" target="_blank">New-Module</a>.</p>
<p><strong>Examples:</strong></p>
<p>Create a new dynamic module using <a href="../2010/03/powershell-2-0-one-cmdlet-at-a-time-71-new-module.html" target="_blank">New-Module</a> containing two variables inside the scriptblock. Export only the variable <strong>$s2</strong> so that it is available for use. <strong>Note:</strong> Export-ModuleMember needs to be included inside the scriptblock.</p>
<pre><span style="color: #5F9EA0; font-weight: bold;">New-Module</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-ScriptBlock</span><span style="color: #000000;"> {</span><span style="color: #800080;">$s1</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;">Server1</span><span style="color: #800000;">'</span><span style="color: #000000;">; </span><span style="color: #800080;">$s2</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;">Server2</span><span style="color: #800000;">'</span><span style="color: #000000;">;
 </span><span style="color: #5F9EA0; font-weight: bold;">Export-ModuleMember</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-Variable</span><span style="color: #000000;"> </span><span style="color: #800000;">s2</span><span style="color: #000000;">}</span></pre>
<p>You will notice that <strong>$s1</strong> is not available in the current session, but <strong>$s2</strong> is.</p>
<p><a rel="attachment wp-att-974" href="http://www.jonathanmedd.net/2010/03/powershell-2-0-one-cmdlet-at-a-time-72-export-modulemember.html/export-modulemember1"><img class="aligncenter size-full wp-image-974" title="Export-ModuleMember1" src="http://www.jonathanmedd.net/wp-content/uploads/2010/03/Export-ModuleMember1.png" alt="Export-ModuleMember1" width="504" height="103" /></a></p>
<p>The other area to use this cmdlet is within a *.psm1 script module file.  In the below example by default all functions would be exported if the Export-ModuleMember cmdlet was not used. However, by using the Export-ModuleMember cmdlet we can control which functions are exported and also export aliases.</p>
<p>So in the example below the <strong>Write-Logfile</strong> and <strong>Greet-User</strong> functions would be exported, but the <strong>Yesterdays-Date</strong> function would not. In addition the <strong>gu</strong> alias would be exported.</p>
<p><a rel="attachment wp-att-980" href="http://www.jonathanmedd.net/2010/03/powershell-2-0-one-cmdlet-at-a-time-72-export-modulemember.html/export-modulemember2"><img class="aligncenter size-full wp-image-980" title="Export-ModuleMember2" src="http://www.jonathanmedd.net/wp-content/uploads/2010/03/Export-ModuleMember2.png" alt="Export-ModuleMember2" width="564" height="236" /></a></p>
<p><strong>How could I have done this in PowerShell 1.0?</strong></p>
<p>This functionality was not avaliable with snapins in PowerShell 1.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/03/powershell-2-0-one-cmdlet-at-a-time-72-export-modulemember.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell 2.0: One Cmdlet at a Time #71 New-Module</title>
		<link>http://www.jonathanmedd.net/2010/03/powershell-2-0-one-cmdlet-at-a-time-71-new-module.html</link>
		<comments>http://www.jonathanmedd.net/2010/03/powershell-2-0-one-cmdlet-at-a-time-71-new-module.html#comments</comments>
		<pubDate>Thu, 04 Mar 2010 13:38:07 +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=961</guid>
		<description><![CDATA[Continuing the series looking at new cmdlets available in PowerShell        2.0. This time we look at the New-Module cmdlet.
What can I do with it?
PowerShell 2.0 introduces the concept of modules; essentially they  are  the evolution of snapins from PowerShell 1.0. New-Module enables  you to create [...]]]></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=141554" target="_blank">New-Module</a> cmdlet.</p>
<p><strong>What can I do with it?</strong></p>
<p>PowerShell 2.0 introduces the concept of modules; essentially they  are  the evolution of snapins from PowerShell 1.0. New-Module enables  you to create a dynamic module from a script block that is available in the current session.</p>
<p><strong>Note:</strong> New-Module does not create a module on disk available for use at a later date! However, <a href="http://twitter.com/jsnover" target="_blank">Jeffrey Snover</a> has created a <a href="http://blogs.msdn.com/powershell/archive/2009/01/02/a-module-to-create-modules-and-advanced-functions.aspx" target="_blank">module</a> which will create a template for a new module on disk for you.</p>
<p><strong>Examples:</strong></p>
<p>Create a new dynamic module with the Function <strong>Write-Logfile</strong> as the scriptblock to create the module. Test to see whether the function is available from <a href="../2009/11/powershell-2-0-one-cmdlet-at-a-time-8-get-module.html" target="_blank">Get-Module</a> or Get-Command.</p>
<pre><span style="color: #5F9EA0; font-weight: bold;">New-Module</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-ScriptBlock</span><span style="color: #000000;">
{</span><span style="color: #0000FF;">Function</span><span style="color: #000000;"> </span><span style="color: #5F9EA0;">Write-Logfile</span><span style="color: #000000;"> (</span><span style="color: #800080;">$log</span><span style="color: #000000;">) {</span><span style="color: #800080;">$Logfile</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;">C:\Log.txt</span><span style="color: #800000;">"</span><span style="color: #000000;">; </span><span style="color: #800080;">$log</span><span style="color: #000000;">
| </span><span style="color: #5F9EA0; font-weight: bold;">Out-File</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-FilePath</span><span style="color: #000000;"> </span><span style="color: #800080;">$Logfile</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-Append</span><span style="color: #000000;">}}
</span><span style="color: #5F9EA0; font-weight: bold;">Get-Module</span><span style="color: #000000;">
</span><span style="color: #5F9EA0; font-weight: bold;">Get-Command</span><span style="color: #000000;"> </span><span style="color: #5F9EA0;">Write-Logfile</span></pre>
<p>You will see that <a href="../2009/11/powershell-2-0-one-cmdlet-at-a-time-8-get-module.html" target="_blank">Get-Module</a> is not aware of the new module, but Get-Command is aware of the <strong>Write-Logfile</strong> function.</p>
<p><a rel="attachment wp-att-962" href="http://www.jonathanmedd.net/2010/03/powershell-2-0-one-cmdlet-at-a-time-71-new-module.html/new-module1"><img class="aligncenter size-full wp-image-962" title="New-Module1" src="http://www.jonathanmedd.net/wp-content/uploads/2010/03/New-Module1.png" alt="New-Module1" width="589" height="152" /></a></p>
<p>Create a new dynamic module with the Function <strong>Write-Logfile</strong> as  the scriptblock to create the module. Give it a name and use <a href="http://www.jonathanmedd.net/2010/03/powershell-2-0-one-cmdlet-at-a-time-70-import-module.html" target="_blank">Import-Module</a> to make it available to <a href="../2009/11/powershell-2-0-one-cmdlet-at-a-time-8-get-module.html" target="_blank">Get-Module</a>.   Test to see whether the function  is available from <a href="../2009/11/powershell-2-0-one-cmdlet-at-a-time-8-get-module.html" target="_blank">Get-Module</a> or Get-Command.</p>
<pre><span style="color: #5F9EA0; font-weight: bold;">New-Module</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-ScriptBlock</span><span style="color: #000000;">
{</span><span style="color: #0000FF;">Function</span><span style="color: #000000;"> </span><span style="color: #5F9EA0;">Write-Logfile</span><span style="color: #000000;"> (</span><span style="color: #800080;">$log</span><span style="color: #000000;">) {</span><span style="color: #800080;">$Logfile</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;">C:\Log.txt</span><span style="color: #800000;">"</span><span style="color: #000000;">; </span><span style="color: #800080;">$log</span><span style="color: #000000;">
| </span><span style="color: #5F9EA0; font-weight: bold;">Out-File</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-FilePath</span><span style="color: #000000;"> </span><span style="color: #800080;">$Logfile</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-Append</span><span style="color: #000000;">}} </span><span style="color: #5F9EA0; font-style: italic;">-Name</span><span style="color: #000000;"> </span><span style="color: #800000;">LogfileModule</span><span style="color: #000000;">
| </span><span style="color: #5F9EA0; font-weight: bold;">Import-Module</span><span style="color: #000000;">
</span><span style="color: #5F9EA0; font-weight: bold;">Get-Module</span><span style="color: #000000;">
</span><span style="color: #5F9EA0; font-weight: bold;">Get-Command</span><span style="color: #000000;"> </span><span style="color: #5F9EA0;">Write-Logfile</span></pre>
<p>You will see that this time both <a href="../2009/11/powershell-2-0-one-cmdlet-at-a-time-8-get-module.html" target="_blank">Get-Module</a> and Get-Command are aware of the <strong>LogfileModule</strong> and <strong>Write-Logfile</strong> function.</p>
<p><a rel="attachment wp-att-963" href="http://www.jonathanmedd.net/2010/03/powershell-2-0-one-cmdlet-at-a-time-71-new-module.html/new-module2"><img class="aligncenter size-full wp-image-963" title="New-Module2" src="http://www.jonathanmedd.net/wp-content/uploads/2010/03/New-Module2.png" alt="New-Module2" width="590" height="145" /></a></p>
<p><strong>How could I have done this in PowerShell 1.0?</strong></p>
<p>You could have created a custom snapin and imported with the Add-PSSnapin cmdlet.</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/03/powershell-2-0-one-cmdlet-at-a-time-71-new-module.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reporting on VMware Update Manager Baselines with PowerCLI</title>
		<link>http://www.jonathanmedd.net/2010/03/reporting-on-vmware-update-manager-baselines-with-powercli.html</link>
		<comments>http://www.jonathanmedd.net/2010/03/reporting-on-vmware-update-manager-baselines-with-powercli.html#comments</comments>
		<pubDate>Wed, 03 Mar 2010 23:21:28 +0000</pubDate>
		<dc:creator>Jonathan Medd</dc:creator>
				<category><![CDATA[powercli]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[vmware]]></category>

		<guid isPermaLink="false">http://www.jonathanmedd.net/?p=942</guid>
		<description><![CDATA[I&#8217;ve mentioned on this blog before that I&#8217;ve been using VMware Update Manager a lot recently &#8211; and wrote about some of my experiences here. Today I was really pleased to see that Carter Shanklin&#8217;s team released some cmdlets for PowerCLI to cover Update Manager which had only previously been available back as a beta [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve mentioned on this blog before that I&#8217;ve been using VMware Update Manager a lot recently &#8211; and wrote about some of my experiences <a href="http://www.simple-talk.com/sysadmin/virtualization/using-vmware-vcenter-update-manager-to-keep-your-vsphere-hosts-up-to-date-with-patching/" target="_blank">here</a>. Today I was really pleased to see that <a href="http://twitter.com/powercli" target="_blank">Carter Shanklin&#8217;s</a> team <a href="http://blogs.vmware.com/vipowershell/2010/03/now-available-powercli-cmdlets-for-vcenter-update-manager.html" target="_blank">released some cmdlets</a> for PowerCLI to cover Update Manager which had only previously been available back as a beta in the VI Toolkit days.</p>
<p>They arrived just in time because I am currently preparing for a round of ESX patching and I needed to provide a report of hotfixes I was intending to deploy for a particular version of ESX. In the Update Manager GUI I had already created my baseline and scanned it against a host to produce a compliance report of hotfixes we would need to deploy this time.</p>
<p>You can see below that it produces a nice report for me, but I needed to export that information to a format whereby I can give that information to someone else.</p>
<p><a rel="attachment wp-att-949" href="http://www.jonathanmedd.net/2010/03/reporting-on-vmware-update-manager-baselines-with-powercli.html/updatemanager1-2"><img class="aligncenter size-full wp-image-949" title="UpdateManager1" src="http://www.jonathanmedd.net/wp-content/uploads/2010/03/UpdateManager11.PNG" alt="UpdateManager1" width="568" height="273" /></a></p>
<p>One of the new cmdlets is <strong>Get-Baseline</strong>. I pointed this at my test baseline and with the code below was quickly able to get the information I needed out into a CSV file. I knew from the above report that I just needed to select any patches since 29/12/2009. One of the properties of the patches returned by Get-Baseline is the date it was published so first of all I set a date for which I could query after and stored it in the $BeginDate variable, I then queried the baseline using that date as a starting point.</p>
<pre><span style="color: #800080;">$BeginDate</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> (</span><span style="color: #5F9EA0; font-weight: bold;">Get-Date</span><span style="color: #000000;">).adddays(</span><span style="color: #FF0000;">-</span><span style="color: #000000;">65</span><span style="color: #000000;">)
</span><span style="color: #5F9EA0; font-weight: bold;">Get-Baseline</span><span style="color: #000000;"> </span><span style="color: #800000;">Test</span><span style="color: #000000;"> | </span><span style="color: #5F9EA0; font-weight: bold;">Select-Object</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-ExpandProperty</span><span style="color: #000000;"> </span><span style="color: #800000;">currentpatches</span><span style="color: #000000;">
| </span><span style="color: #5F9EA0; font-weight: bold;">Where-Object</span><span style="color: #000000;"> {</span><span style="color: #800080;">$_</span><span style="color: #000000;">.</span><span style="color: #800000;">'</span><span style="color: #800000;">releasedate</span><span style="color: #800000;">'</span><span style="color: #000000;"> </span><span style="color: #FF0000;">-gt</span><span style="color: #000000;"> </span><span style="color: #800080;">$BeginDate</span><span style="color: #000000;">}
| </span><span style="color: #5F9EA0; font-weight: bold;">Select-Object</span><span style="color: #000000;"> Name,IDByVendor,Description,@{n</span><span style="color: #FF0000;">=</span><span style="color: #800000;">'</span><span style="color: #800000;">Product</span><span style="color: #800000;">'</span><span style="color: #000000;">;e</span><span style="color: #FF0000;">=</span><span style="color: #000000;">{</span><span style="color: #800080;">$_</span><span style="color: #000000;">.product | </span><span style="color: #5F9EA0; font-weight: bold;">Select-Object</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-expandproperty</span><span style="color: #000000;"> </span><span style="color: #800000;">Version</span><span style="color: #000000;">}},ReleaseDate
| </span><span style="color: #5F9EA0; font-weight: bold;">Export-Csv</span><span style="color: #000000;"> </span><span style="color: #800000;">patches.csv</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-NoTypeInformation</span></pre>
<p>Which produces an output like this:</p>
<p><a rel="attachment wp-att-948" href="http://www.jonathanmedd.net/2010/03/reporting-on-vmware-update-manager-baselines-with-powercli.html/updatemanager2-3"><img class="aligncenter size-full wp-image-948" title="UpdateManager2" src="http://www.jonathanmedd.net/wp-content/uploads/2010/03/UpdateManager22.PNG" alt="UpdateManager2" width="600" height="194" /></a></p>
<p>You&#8217;ll notice that I make use of the <strong>ExpandProperty</strong> parameter for <a href="http://technet.microsoft.com/en-us/library/dd315291.aspx" target="_blank">Select-Object</a> which makes it nice and easy to get to properties which are returned in an array, otherwise although they look fine in the console, when you export them to CSV you will not get what you hope for.</p>
<p>It&#8217;s days like today when I&#8217;m especially glad I started using PowerShell and very thankful that the vendors of technologies I&#8217;m using make this stuff so simple by providing cmdlets for managing their products.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonathanmedd.net/2010/03/reporting-on-vmware-update-manager-baselines-with-powercli.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>PowerShell 2.0: One Cmdlet at a Time #70 Import-Module</title>
		<link>http://www.jonathanmedd.net/2010/03/powershell-2-0-one-cmdlet-at-a-time-70-import-module.html</link>
		<comments>http://www.jonathanmedd.net/2010/03/powershell-2-0-one-cmdlet-at-a-time-70-import-module.html#comments</comments>
		<pubDate>Wed, 03 Mar 2010 13:35:30 +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=936</guid>
		<description><![CDATA[Continuing the series looking at new cmdlets available in PowerShell       2.0. This time we look at the Import-Module cmdlet.
What can I do with it?
PowerShell 2.0 introduces the concept of modules; essentially they are  the evolution of snapins from PowerShell 1.0. Import-Module enables you to add one or more [...]]]></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=141553" target="_blank">Import-Module </a>cmdlet.</p>
<p><strong>What can I do with it?</strong></p>
<p>PowerShell 2.0 introduces the concept of modules; essentially they are  the evolution of snapins from PowerShell 1.0. Import-Module enables you to add one or more modules to your current session.</p>
<p><strong>Examples:</strong></p>
<p>Import the <strong>PSDiagnostics</strong> module and examine the newly available commands in the session from that module by using <a href="http://www.jonathanmedd.net/2009/11/powershell-2-0-one-cmdlet-at-a-time-8-get-module.html" target="_blank">Get-Module</a>.</p>
<pre><span style="color: #5F9EA0; font-weight: bold;">Import-Module</span><span style="color: #000000;"> </span><span style="color: #800000;">PSDiagnostics</span><span style="color: #000000;">
</span><span style="color: #5F9EA0; font-weight: bold;">Get-Command</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-Module</span><span style="color: #000000;"> </span><span style="color: #800000;">PSDiagnostics</span></pre>
<p>You will see there are ten new functions available from that module.</p>
<p><a rel="attachment wp-att-937" href="http://www.jonathanmedd.net/2010/03/powershell-2-0-one-cmdlet-at-a-time-70-import-module.html/import-module1"><img class="aligncenter size-full wp-image-937" title="Import-Module1" src="http://www.jonathanmedd.net/wp-content/uploads/2010/03/Import-Module1.png" alt="Import-Module1" width="491" height="201" /></a></p>
<p>Import only two functions, <strong>Start-Trace</strong> and <strong>Stop-Trace</strong> from the <strong>PSDiagnostics</strong> module and examine the newly available  commands in the session from that module by using <a href="../2009/11/powershell-2-0-one-cmdlet-at-a-time-8-get-module.html" target="_blank">Get-Module</a>.</p>
<pre><span style="color: #5F9EA0; font-weight: bold;">Import-Module</span><span style="color: #000000;"> </span><span style="color: #800000;">PSDiagnostics</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-Function</span><span style="color: #000000;"> Start-Trace,Stop-Trace
</span><span style="color: #5F9EA0; font-weight: bold;">Get-Command</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-Module</span><span style="color: #000000;"> </span><span style="color: #800000;">PSDiagnostics</span></pre>
<p>You will see that this time only those two functions are available.</p>
<p><a rel="attachment wp-att-938" href="http://www.jonathanmedd.net/2010/03/powershell-2-0-one-cmdlet-at-a-time-70-import-module.html/import-module2"><img class="aligncenter size-full wp-image-938" title="Import-Module2" src="http://www.jonathanmedd.net/wp-content/uploads/2010/03/Import-Module2.png" alt="Import-Module2" width="499" height="130" /></a></p>
<p><strong>How could I have done this in PowerShell 1.0?</strong></p>
<p>You could have used the Add-PSSnapin cmdlet to import custom snapins typically produced by third-parties. For example to import the popular Quest AD cmdlets snapin you would use the below:</p>
<pre><span style="color: #5F9EA0; font-weight: bold;">Add-PSSnapin</span><span style="color: #000000;"> </span><span style="color: #800000;">Quest.ActiveRoles.ADManagement</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/03/powershell-2-0-one-cmdlet-at-a-time-70-import-module.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell 2.0: One Cmdlet at a Time #69 Get-WinEvent</title>
		<link>http://www.jonathanmedd.net/2010/03/powershell-2-0-one-cmdlet-at-a-time-69-get-winevent.html</link>
		<comments>http://www.jonathanmedd.net/2010/03/powershell-2-0-one-cmdlet-at-a-time-69-get-winevent.html#comments</comments>
		<pubDate>Tue, 02 Mar 2010 12:03:11 +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=929</guid>
		<description><![CDATA[Continuing the series looking at new cmdlets available in PowerShell      2.0. This time we look at the Get-WinEvent cmdlet.
What can I do with it?
Retrieve items from Event Logs including event logs generated by the Windows Event Log technology, new since Windows Vista / 2008 Server, in addition to the classic [...]]]></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=138336" target="_blank">Get-WinEvent</a> cmdlet.</p>
<p><strong>What can I do with it?</strong></p>
<p>Retrieve items from Event Logs including event logs generated by the Windows Event Log technology, new since Windows Vista / 2008 Server, in addition to the classic System, Security and Application Logs. <strong>Note:</strong> it requires .NET Framework 3.5 or later installed.</p>
<p><strong>Examples:</strong></p>
<p>Retrieve events from the <strong>Setup</strong> Event Log.</p>
<pre><span style="color: #5F9EA0; font-weight: bold;">Get-WinEvent</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-LogName</span><span style="color: #000000;"> </span><span style="color: #800000;">Setup</span></pre>
<p>You&#8217;ll see the typical information you would normally view in Event Viewer.</p>
<p><a rel="attachment wp-att-931" href="http://www.jonathanmedd.net/2010/03/powershell-2-0-one-cmdlet-at-a-time-69-get-winevent.html/get-winevent1"><img class="aligncenter size-full wp-image-931" title="Get-WinEvent1" src="http://www.jonathanmedd.net/wp-content/uploads/2010/03/Get-WinEvent1.png" alt="Get-WinEvent1" width="592" height="99" /></a></p>
<p>Get-WinEvent includes a<strong> -FilterHashTable</strong> parameter which allows you to filter results at source rather than pulling back all the events and then piping them through to Where-Object to perform filtering, so much more effiicient.</p>
<p>Retrieve events from the <strong>System</strong> Event Log only where the <strong>Event ID</strong> is <strong>10148</strong>.</p>
<pre><span style="color: #5F9EA0; font-weight: bold;">Get-WinEvent</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-FilterHashtable</span><span style="color: #000000;"> @{Logname</span><span style="color: #FF0000;">=</span><span style="color: #800000;">'</span><span style="color: #800000;">System</span><span style="color: #800000;">'</span><span style="color: #000000;">;ID</span><span style="color: #FF0000;">=</span><span style="color: #000000;">10148</span><span style="color: #000000;">}</span></pre>
<p>You will see that only the events with <strong>ID 10148</strong> are returned.</p>
<p><a rel="attachment wp-att-932" href="http://www.jonathanmedd.net/2010/03/powershell-2-0-one-cmdlet-at-a-time-69-get-winevent.html/get-winevent2"><img class="aligncenter size-full wp-image-932" title="Get-WinEvent2" src="http://www.jonathanmedd.net/wp-content/uploads/2010/03/Get-WinEvent2.png" alt="Get-WinEvent2" width="591" height="90" /></a></p>
<p><strong>How could I have done this in PowerShell 1.0?</strong></p>
<p>You could have used the Get-EventLog cmdlet, however it is not able to retrieve information from event logs generated by the Windows Event Log technology such as the Setup log mentioned in the above examples.</p>
<pre><span style="color: #5F9EA0; font-weight: bold;">Get-EventLog</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-LogName</span><span style="color: #000000;"> </span><span style="color: #800000;">System</span><span style="color: #000000;"> | </span><span style="color: #5F9EA0; font-weight: bold;">Where-Object</span><span style="color: #000000;"> {</span><span style="color: #800080;">$_</span><span style="color: #000000;">.EventID </span><span style="color: #FF0000;">-eq</span><span style="color: #000000;"> </span><span style="color: #000000;">10148</span><span style="color: #000000;">}</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/03/powershell-2-0-one-cmdlet-at-a-time-69-get-winevent.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell 2.0: One Cmdlet at a Time #68 Show-EventLog</title>
		<link>http://www.jonathanmedd.net/2010/02/powershell-2-0-one-cmdlet-at-a-time-68-show-eventlog.html</link>
		<comments>http://www.jonathanmedd.net/2010/02/powershell-2-0-one-cmdlet-at-a-time-68-show-eventlog.html#comments</comments>
		<pubDate>Fri, 26 Feb 2010 13:26:08 +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=920</guid>
		<description><![CDATA[Continuing the series looking at new cmdlets available in PowerShell     2.0. This time we look at the Show-EventLog cmdlet.
What can I do with it?
Open Event Viewer on a local or remote computer.
Example:
Open Event Viewer on the remote computer Test01.
Show-EventLog -ComputerName Test01
You will see that Event Viewer on the remote computer Test01 [...]]]></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=135257" target="_blank">Show-EventLog</a> cmdlet.</p>
<p><strong>What can I do with it?</strong></p>
<p>Open Event Viewer on a local or remote computer.</p>
<p><strong>Example:</strong></p>
<p>Open Event Viewer on the remote computer <strong>Test01</strong>.</p>
<pre><span style="color: #5F9EA0; font-weight: bold;">Show-EventLog</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-ComputerName</span><span style="color: #000000;"> </span><span style="color: #800000;">Test01</span></pre>
<p>You will see that Event Viewer on the remote computer <strong>Test01</strong> opens on the local machine.</p>
<p><a rel="attachment wp-att-921" href="http://www.jonathanmedd.net/2010/02/powershell-2-0-one-cmdlet-at-a-time-68-show-eventlog.html/show-eventlog"><img class="aligncenter size-full wp-image-921" title="Show-EventLog" src="http://www.jonathanmedd.net/wp-content/uploads/2010/02/Show-EventLog.png" alt="Show-EventLog" width="479" height="206" /></a></p>
<p><strong>How could I have done this in PowerShell 1.0?</strong></p>
<p>You could have typed the executable <strong>Eventvwr</strong> to open Event Viewer on a local computer. To view it on the remote computer <strong>Test01</strong> use:</p>
<p>eventvwr \\Test01</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/02/powershell-2-0-one-cmdlet-at-a-time-68-show-eventlog.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell 2.0: One Cmdlet at a Time #67 Remove-EventLog</title>
		<link>http://www.jonathanmedd.net/2010/02/powershell-2-0-one-cmdlet-at-a-time-67-remove-eventlog.html</link>
		<comments>http://www.jonathanmedd.net/2010/02/powershell-2-0-one-cmdlet-at-a-time-67-remove-eventlog.html#comments</comments>
		<pubDate>Fri, 26 Feb 2010 13:06: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=910</guid>
		<description><![CDATA[Continuing the series looking at new cmdlets available in PowerShell    2.0. This time we look at the Remove-EventLog cmdlet.
What can I do with it?
Remove an Event Log.
Example:
Remove the Event Log named App1 on the remote computer Test01. Confirm it has been removed with Get-EventLog.
Remove-EventLog -LogName App1 -ComputerName Test01
Get-EventLog -List -ComputerName Test01
Confirmation that [...]]]></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=135248" target="_blank">Remove-EventLog</a> cmdlet.</p>
<p><strong>What can I do with it?</strong></p>
<p>Remove an Event Log.</p>
<p><strong>Example:</strong></p>
<p>Remove the Event Log named <strong>App1 </strong>on the remote computer <strong>Test01</strong>. Confirm it has been removed with Get-EventLog.</p>
<pre><span style="color: #5F9EA0; font-weight: bold;">Remove-EventLog</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-LogName</span><span style="color: #000000;"> </span><span style="color: #800000;">App1</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-ComputerName</span><span style="color: #000000;"> </span><span style="color: #800000;">Test01</span><span style="color: #000000;">
</span><span style="color: #5F9EA0; font-weight: bold;">Get-EventLog</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-List</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-ComputerName</span><span style="color: #000000;"> </span><span style="color: #800000;">Test01</span></pre>
<p>Confirmation that the <strong>App1</strong> Event Log has been removed.</p>
<p><a rel="attachment wp-att-911" href="http://www.jonathanmedd.net/2010/02/powershell-2-0-one-cmdlet-at-a-time-67-remove-eventlog.html/remove-eventlog1"><img class="aligncenter size-full wp-image-911" title="Remove-EventLog1" src="http://www.jonathanmedd.net/wp-content/uploads/2010/02/Remove-EventLog1.png" alt="Remove-EventLog1" width="428" height="161" /></a></p>
<p><strong>Note:</strong> To perform this task remotely you will need to ensure that <strong>Remote Event Log Management</strong> has been added as an Exception in Windows Firewall.</p>
<p><a rel="attachment wp-att-912" href="http://www.jonathanmedd.net/2010/02/powershell-2-0-one-cmdlet-at-a-time-67-remove-eventlog.html/remove-eventlog2"><img class="aligncenter size-full wp-image-912" title="Remove-EventLog2" src="http://www.jonathanmedd.net/wp-content/uploads/2010/02/Remove-EventLog2.png" alt="Remove-EventLog2" width="429" height="261" /></a></p>
<p><strong>How could I have done this in PowerShell 1.0?</strong></p>
<p>You could have have used the .NET <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.aspx" target="_blank">System.Diagnostics.Eventlog</a> class and the Delete method to delete an event log.</p>
<pre><span style="color: #000000;">[</span><span style="color: #008080;">system.diagnostics.eventlog</span><span style="color: #000000;">]::</span><span style="color: #8B4513;">Delete</span><span style="color: #000000;">(</span><span style="color: #800000;">"</span><span style="color: #800000;">App1</span><span style="color: #800000;">"</span><span style="color: #000000;">)

</span><a href="http://blogs.msdn.com/powershell/archive/2008/09/19/a-thousand-things-1-better.aspx" target="_blank">1000 things 1% better!</a>
<span style="color: #000000;">
</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.jonathanmedd.net/2010/02/powershell-2-0-one-cmdlet-at-a-time-67-remove-eventlog.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bug in Cluster mem.usage.average Statistic in vSphere 4.0 U1</title>
		<link>http://www.jonathanmedd.net/2010/02/bug-in-cluster-mem-usage-average-statistic-in-vsphere-4-0-u1.html</link>
		<comments>http://www.jonathanmedd.net/2010/02/bug-in-cluster-mem-usage-average-statistic-in-vsphere-4-0-u1.html#comments</comments>
		<pubDate>Tue, 23 Feb 2010 21:36:25 +0000</pubDate>
		<dc:creator>Jonathan Medd</dc:creator>
				<category><![CDATA[powercli]]></category>
		<category><![CDATA[vmware]]></category>

		<guid isPermaLink="false">http://www.jonathanmedd.net/?p=890</guid>
		<description><![CDATA[A while back I posted a script on a basic capacity report I run each month to get an overview of CPU and Memory usage in our various clusters. Since upgrading to vSphere 4.0 U1 I noticed some strange behavior in the results for memory, i.e. they came back at pretty close to 0% (typically [...]]]></description>
			<content:encoded><![CDATA[<p>A while back I <a href="http://www.jonathanmedd.net/2009/09/average-cpu-and-memory-use-per-host-per-cluster.html" target="_blank">posted a script on a basic capacity report</a> I run each month to get an overview of CPU and Memory usage in our various clusters. Since upgrading to vSphere 4.0 U1 I noticed some strange behavior in the results for memory, i.e. they came back at pretty close to 0% (typically between 0.05 and 0.06%) for the average memory usage in a cluster which typically were quite heavily used. On investigating further this also appeared the same in the GUI.</p>
<p>Using Get-Stat, mem.usage.average comes back at 0% where it should be a significant value:</p>
<p><a rel="attachment wp-att-898" href="http://www.jonathanmedd.net/2010/02/bug-in-cluster-mem-usage-average-statistic-in-vsphere-4-0-u1.html/memusageaverage1-2"><img class="aligncenter size-full wp-image-898" title="memusageaverage1" src="http://www.jonathanmedd.net/wp-content/uploads/2010/02/memusageaverage11.PNG" alt="memusageaverage1" width="568" height="144" /></a></p>
<p>The same in the GUI, the other cluster memory stats have significant values, but Memory Usage Average flatlines along the bottom of the graph:</p>
<p><a rel="attachment wp-att-895" href="http://www.jonathanmedd.net/2010/02/bug-in-cluster-mem-usage-average-statistic-in-vsphere-4-0-u1.html/memusageaverage2-2"><img class="aligncenter size-full wp-image-895" title="memusageaverage2" src="http://www.jonathanmedd.net/wp-content/uploads/2010/02/memusageaverage21.PNG" alt="memusageaverage2" width="630" height="400" /></a></p>
<p>This stat shows normal behaviour against host machines. I reported it to VMware who confirmed it to be a bug in 4.0 U1.</p>
<p>Thought I would share in case anyone else spends some time scratching their head and checking maths in scripts like I did. I&#8217;ll post back when there is a fix.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonathanmedd.net/2010/02/bug-in-cluster-mem-usage-average-statistic-in-vsphere-4-0-u1.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PowerShell 2.0: One Cmdlet at a Time #66 Limit-EventLog</title>
		<link>http://www.jonathanmedd.net/2010/02/powershell-2-0-one-cmdlet-at-a-time-66-limit-eventlog.html</link>
		<comments>http://www.jonathanmedd.net/2010/02/powershell-2-0-one-cmdlet-at-a-time-66-limit-eventlog.html#comments</comments>
		<pubDate>Tue, 23 Feb 2010 15:06:23 +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=883</guid>
		<description><![CDATA[Continuing the series looking at new cmdlets available in PowerShell   2.0. This time we look at the Limit-EventLog cmdlet.
What can I do with it?
Set the size and age properties of an Event Log.
Example:
Set the following properties on the Application Log on the remote computer Test01:
Maximum Size = 5MB
OverflowAction = DoNotOverWrite
Limit-EventLog -ComputerName Test01 -LogName [...]]]></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=135227" target="_blank">Limit-EventLog</a> cmdlet.</p>
<p><strong>What can I do with it?</strong></p>
<p>Set the size and age properties of an Event Log.</p>
<p><strong>Example:</strong></p>
<p>Set the following properties on the <strong>Application Log</strong> on the remote computer <strong>Test01</strong>:</p>
<p>Maximum Size = 5MB</p>
<p>OverflowAction = DoNotOverWrite</p>
<pre><span style="color: #5F9EA0; font-weight: bold;">Limit-EventLog</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-ComputerName</span><span style="color: #000000;"> </span><span style="color: #800000;">Test01</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-LogName</span><span style="color: #000000;"> </span><span style="color: #800000;">Application</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">
-MaximumSize</span><span style="color: #000000;"> 5MB </span><span style="color: #5F9EA0; font-style: italic;">-OverflowAction</span><span style="color: #000000;"> </span><span style="color: #800000;">DoNotOverWrite</span></pre>
<p><a rel="attachment wp-att-884" href="http://www.jonathanmedd.net/2010/02/powershell-2-0-one-cmdlet-at-a-time-66-limit-eventlog.html/limit-eventlog1"><img class="aligncenter size-full wp-image-884" title="Limit-EventLog1" src="http://www.jonathanmedd.net/wp-content/uploads/2010/02/Limit-EventLog1.png" alt="Limit-EventLog1" width="589" height="44" /></a></p>
<p><strong>Before:</strong></p>
<p><a rel="attachment wp-att-885" href="http://www.jonathanmedd.net/2010/02/powershell-2-0-one-cmdlet-at-a-time-66-limit-eventlog.html/limit-eventlog2"><img class="aligncenter size-full wp-image-885" title="Limit-EventLog2" src="http://www.jonathanmedd.net/wp-content/uploads/2010/02/Limit-EventLog2.png" alt="Limit-EventLog2" width="393" height="131" /></a></p>
<p><strong>After:</strong></p>
<p><a rel="attachment wp-att-886" href="http://www.jonathanmedd.net/2010/02/powershell-2-0-one-cmdlet-at-a-time-66-limit-eventlog.html/limit-eventlog3"><img class="aligncenter size-full wp-image-886" title="Limit-EventLog3" src="http://www.jonathanmedd.net/wp-content/uploads/2010/02/Limit-EventLog3.png" alt="Limit-EventLog3" width="362" height="129" /></a></p>
<p><strong>How could I have done this in PowerShell 1.0?</strong></p>
<p>You could use WMI to set properties on an event log. For example to set the <strong>MaxFileSize</strong> of the <strong>Application Log</strong> to <strong>5MB</strong> use the below. (Thanks to <a href="http://richardsiddaway.spaces.live.com/blog/cns!43CFA46A74CF3E96!1816.entry" target="_blank">Richard Siddaway for the tip</a> that you need to use psbase to save the changes, just <strong>Put()</strong> doesn&#8217;t work.)</p>
<pre><span style="color: #800080;">$EventLog</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-weight: bold;">Get-WmiObject</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-Class</span><span style="color: #000000;"> </span><span style="color: #800000;">Win32_NTEventLogFile</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">
-Filter</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">LogFileName = 'Application'</span><span style="color: #800000;">"</span><span style="color: #000000;">
</span><span style="color: #800080;">$EventLog</span><span style="color: #000000;">.MaxFileSize </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #000000;">5242880</span><span style="color: #000000;">
</span><span style="color: #800080;">$EventLog</span><span style="color: #000000;">.psbase.Put()</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/02/powershell-2-0-one-cmdlet-at-a-time-66-limit-eventlog.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell 2.0: One Cmdlet at a Time #65 New-EventLog</title>
		<link>http://www.jonathanmedd.net/2010/02/powershell-2-0-one-cmdlet-at-a-time-65-new-eventlog.html</link>
		<comments>http://www.jonathanmedd.net/2010/02/powershell-2-0-one-cmdlet-at-a-time-65-new-eventlog.html#comments</comments>
		<pubDate>Mon, 22 Feb 2010 22:26:38 +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=869</guid>
		<description><![CDATA[Continuing the series looking at new cmdlets available in PowerShell  2.0. This time we look at the New-EventLog cmdlet.
What can I do with it?
Create a custom Event Log.
Example:
Create a custom Event Log named App1 with an event source of AppEvent. Use the Get-EventLog cmdlet to confirm it has been created. Tip: New-EventLog requires 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=135235" target="_blank">New-EventLog</a> cmdlet.</p>
<p><strong>What can I do with it?</strong></p>
<p>Create a custom Event Log.</p>
<p><strong>Example:</strong></p>
<p>Create a custom Event Log named <strong>App1</strong> with an event source of <strong>AppEvent</strong>. Use the Get-EventLog cmdlet to confirm it has been created. <strong>Tip</strong>: New-EventLog requires a PowerShell session with elevated  privileges.</p>
<pre><span style="color: #5F9EA0; font-weight: bold;">New-EventLog</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-LogName</span><span style="color: #000000;"> </span><span style="color: #800000;">App1</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-Source</span><span style="color: #000000;"> </span><span style="color: #800000;">AppEvent</span><span style="color: #000000;">
</span><span style="color: #5F9EA0; font-weight: bold;">Get-EventLog</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-List</span></pre>
<p>You can see that the <strong>App1</strong> Event Log has been created.</p>
<p><a rel="attachment wp-att-871" href="http://www.jonathanmedd.net/2010/02/powershell-2-0-one-cmdlet-at-a-time-65-new-eventlog.html/new-eventlog1"><img class="aligncenter size-full wp-image-871" title="New-EventLog1" src="http://www.jonathanmedd.net/wp-content/uploads/2010/02/New-EventLog1.png" alt="New-EventLog1" width="562" height="173" /></a></p>
<p>You can create entries in this log using the <a href="http://www.jonathanmedd.net/2009/12/powershell-2-0-one-cmdlet-at-a-time-12-write-eventlog.html" target="_blank">Write-EventLog</a> cmdlet, e.g.</p>
<pre><span style="color: #5F9EA0; font-weight: bold;">Write-EventLog</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-LogName</span><span style="color: #000000;"> </span><span style="color: #800000;">App1</span><span style="color: #000000;"> </span><span style="color: #5F9EA0; font-style: italic;">-Source</span><span style="color: #000000;"> </span><span style="color: #800000;">AppEvent</span><span style="color: #000000;"> -ID </span><span style="color: #000000;">1020</span><span style="color: #000000;">
</span><span style="color: #5F9EA0; font-style: italic;">-Message</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">Error 1020 has occured</span><span style="color: #800000;">"</span></pre>
<p>Here&#8217;s confirmation in Event Viewer that the App1 Event Log exists and we have created the above entry in it.</p>
<p><a rel="attachment wp-att-878" href="http://www.jonathanmedd.net/2010/02/powershell-2-0-one-cmdlet-at-a-time-65-new-eventlog.html/new-eventlog2-2"><img class="aligncenter size-full wp-image-878" title="New-EventLog2" src="http://www.jonathanmedd.net/wp-content/uploads/2010/02/New-EventLog21.PNG" alt="New-EventLog2" width="675" height="183" /></a></p>
<p><strong>How could I have done this in PowerShell 1.0?</strong></p>
<p>You could have used the .NET <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.aspx" target="_blank">System.Diagnostics.EventLog class</a> and the <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.createeventsource.aspx" target="_blank">CreateEventSource method</a> to create a custom event log.</p>
<pre><span style="color: #800080;">$LogDetails</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.Diagnostics.EventSourceCreationData</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">AppEvent</span><span style="color: #800000;">"</span><span style="color: #000000;">, </span><span style="color: #800000;">"</span><span style="color: #800000;">App1</span><span style="color: #800000;">"</span><span style="color: #000000;">
[</span><span style="color: #008080;">System.Diagnostics.EventLog</span><span style="color: #000000;">]::</span><span style="color: #8B4513;">CreateEventSource</span><span style="color: #000000;">(</span><span style="color: #800080;">$LogDetails</span><span style="color: #000000;">)</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/02/powershell-2-0-one-cmdlet-at-a-time-65-new-eventlog.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
