<?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>Use PowerShell &#187; PowerShell Version 1</title>
	<atom:link href="http://blog.usepowershell.com/category/powershell/powershellv1/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.usepowershell.com</link>
	<description>Real Admins Script</description>
	<lastBuildDate>Sat, 17 Jul 2010 14:38:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Script Club &#8211; Coming to the Greater Milwaukee Area</title>
		<link>http://blog.usepowershell.com/2009/12/script-club-coming-to-the-greater-milwaukee-area/</link>
		<comments>http://blog.usepowershell.com/2009/12/script-club-coming-to-the-greater-milwaukee-area/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 16:06:39 +0000</pubDate>
		<dc:creator>Steven Murawski</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell Community]]></category>
		<category><![CDATA[PowerShell Version 1]]></category>
		<category><![CDATA[PowerShell Version 2]]></category>

		<guid isPermaLink="false">http://blog.usepowershell.com/2009/12/script-club-coming-to-the-greater-milwaukee-area/</guid>
		<description><![CDATA[Register here. About PowerShell Script Club 1. You Always Talk About Script club 2. You Always Talk About Script Club 3. If Someone asks for Help, And You Can Help, You Help 4. Two People Help One Person at One Time 5. One Module Per Person Per Night 6. All Scripts, All PowerShell 7. Scripts [...]]]></description>
			<content:encoded><![CDATA[<h3><strong><a href="http://mkescriptclub.eventbrite.com " target="_blank">Register here.</a></strong></h3>
<h3>About PowerShell Script Club</h3>
<p>1. You Always Talk About Script club    <br />2. You Always Talk About Script Club     <br />3. If Someone asks for Help, And You Can Help, You Help     <br />4. Two People Help One Person at One Time     <br />5. One Module Per Person Per Night     <br />6. All Scripts, All PowerShell     <br />7. Scripts will be as short as they can be     <br />8. If This is your First time at Script Club, You Have to Script</p>
<h4>The first Greater Milwaukee <a href="http://msdn.microsoft.com/en-us/library/ms714418(VS.85).aspx" target="_blank">PowerShell</a> Script Club is being formed.</h4>
<p>The first meeting will be on Tuesday, January 19th at 6:00 PM at the Greenfield Law Enforcement Center (in the Municipal Court Room), 5300 W Layton Ave, Greenfield, WI&#160; 53220.&#160; <a href="http://mkescriptclub.eventbrite.com " target="_blank">Register here.</a></p>
<p><strong><u>All</u></strong> <strong>IT Professionals (sysadmins, network admins, developers, help desk, and all others) with <u>any level of experience</u> are welcome.&#160; If you DO NOT KNOW POWERSHELL, but you WANT TO – This is the place.</strong></p>
<p>Pizza and soda will be provided, but please bring a laptop with PowerShell installed (version 1 or 2 is fine).</p>
<h4>What is a Script Club?</h4>
<p><a href="http://get-powershell.com/2009/04/04/powershell-script-club-in-seattle/" target="_blank">Andy Schneider describes a script club:</a></p>
<blockquote><p>Script Clubs are like a hands on lab with no set topic or teacher. You bring an idea for a script, and ask your fellow PowerShell users for help getting the script written.</p>
</blockquote>
<p>This is not a lecture or presentation based group (though we may have presentations from time to time).&#160; Script Club is focused on creating working scripts that will help you get your work done or just enjoy yourself.</p>
<h3><a href="http://mkescriptclub.eventbrite.com/" target="_blank">Register here.</a></h3>
]]></content:encoded>
			<wfw:commentRss>http://blog.usepowershell.com/2009/12/script-club-coming-to-the-greater-milwaukee-area/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Deep Dive: Error Handling &#8211; Error Types (part 1)</title>
		<link>http://blog.usepowershell.com/2009/07/deep-dive-error-handling-error-types-part-1/</link>
		<comments>http://blog.usepowershell.com/2009/07/deep-dive-error-handling-error-types-part-1/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 12:00:00 +0000</pubDate>
		<dc:creator>Steven Murawski</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[Base Class Libraries]]></category>
		<category><![CDATA[Deep Dive]]></category>
		<category><![CDATA[Error Handling]]></category>
		<category><![CDATA[PowerShell Version 1]]></category>
		<category><![CDATA[PowerShell Version 2]]></category>

		<guid isPermaLink="false">http://blog.usepowershell.com/2009/07/deep-dive-error-handling-error-types-part-1/</guid>
		<description><![CDATA[I started looking a little deeper at error handling in PowerShell after this StackOverflow question. PowerShell has two kinds of errors – terminating errors and non-terminating errors. Terminating errors are the errors that can stop command execution cold.  Non-terminating errors provided an additional challenge, as you need to be notified of failed operations and continue [...]]]></description>
			<content:encoded><![CDATA[<p>I started looking a little deeper at error handling in PowerShell after <a href="http://stackoverflow.com/questions/1142211/try-catch-does-not-seem-to-have-an-effect" target="_blank">this StackOverflow question</a>.</p>
<p>PowerShell has two kinds of errors – terminating errors and non-terminating errors.</p>
<p>Terminating errors are the errors that can stop command execution cold.  Non-terminating errors provided an additional challenge, as you need to be notified of failed operations and continue with pipeline operations.  To deal with this issue and to provide additional output options, PowerShell employs the concept of streams.  There are three additional streams (other than the primary pipeline stream) available in PowerShell – Verbose, Warning, and Error (and .  We’ll be concerning ourselves with the output from the Error stream.</p>
<p>There are some <a href="http://technet.microsoft.com/en-us/library/dd347675.aspx" target="_blank">automatic variables</a> in the shell that deal with errors as well.  $ErrorActionPreference is a variable that describes how PowerShell will treat non-terminating errors.  $ErrorActionPreference has four options: “Continue” (the default), “SilentlyContinue”, “Inquire”, and “Stop”.  $error is an array of all the errors that have occurred in the current session up to the number specified in $MaximumErrorCount.  $? is a boolean value that is $true if the previous operation succeeded and $false if it did not.</p>
<p>PowerShell does have some built in flexibility to turn non-terminating errors into terminating errors.  Based on our setting of $ErrorActionPreference, PowerShell will treat a non-terminating error differently.  If $ErrorActionPreference is set to &#8216;”Stop”, PowerShell will treat the errors from that scope and all sub scopes (unless explicitly overridden) as terminating errors.  If “Inquire” is chosen as the $ErrorActionPreference, then PowerShell will prompt the user at the console upon each error to ask whether it should continue (treat as non-terminating) or halt (treat as terminating), as well as providing an option to drop into a nested prompt.</p>
<p>$ErrorActionPreference is a global preference that can be set, but the PowerShell runtime also allows more granular control by providing <a href="http://technet.microsoft.com/en-us/library/dd315352.aspx" target="_blank">common parameters</a> for -ErrorAction and -ErrorVariable (shorthand -EA and –EV) which allow you to determine per cmdlet (and in V2 per advanced function) how errors should be handled.  The –ErrorAction parameter takes the same options as $ErrorActionPreference.</p>
<p>So what happens when you encounter an error?</p>
<p>If you hit a terminating error, your script, function, or command will stop.  The error will be logged to the $error variable and written to the error stream.  The $? will be set to false.  You can use the <a href="http://technet.microsoft.com/en-us/library/dd347548.aspx" target="_blank">trap construct</a> (or the <a href="http://technet.microsoft.com/en-us/library/dd315350.aspx" target="_blank">try/catch/finally construct</a> in V2) to deal with terminating errors and we’ll cover that further in the fourth post in this series.</p>
<p>If you hit a non-terminating error, the result will depend on the $ErrorActionPreference in the scope or the –ErrorAction parameter.  If the $ErrorActionPreference or –ErrorAction parameter is set to ‘Continue’, the error will be written to the error stream, added to the $error array, and the $? will be set to $false.  ‘SilentlyContinue’ will not write an error to the Error stream, but $error and $? are updated.  Finally, ‘Inquire’ provides you an option at each error as to whether to treat it as terminating or non-terminating.  If treated as a non-terminating error, the error will be treated like the $ErrorActionPreference or –ErrorAction parameter is ‘Continue’.</p>
<p>Now, I’ve mentioned that some terminating and non-terminating errors both write to the Error stream, so where does that actually get reported back to the user?  If an error has been written to the error stream, it will be written to the output stream (which may surface differently based on the PowerShell host) separately from the pipeline output unless it is redirected.  This means that the exception objects, which are how the errors are represented, are not saved to a variable if you are assigning the pipeline output to a variable.</p>
<p>For example:</p>
<p>$results = Get-WMIObject Win32_Bios –ComputerName localhost, ComputerThatDoesNotExist<br />
Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)<br />
At line:1 char:22<br />
+ $results = Get-WmiObject  &lt;&lt;&lt;&lt; Win32_Bios -ComputerName localhost, ComputerThatDoesNotExist</p>
<p>creates this output to the screen, but $results will only hold the results of the successful WMI query.  This is where the –ErrorVariable comes in.  You can specify a variable to hold the exceptions generated by a particular cmdlet (or in V2 advanced function).  Specifying a variable does not remove an item from being written to the error stream and displayed as output.</p>
<p>In a console session, you can redirect the error stream with the redirection operators ( 2&gt; or 2&gt;&gt;) or you can merge the error stream with the output stream (2&gt;&amp;1) and write the output to a file, the pipeline, or assign it to a variable.</p>
<p>Up next:</p>
<ul>
<li>Error Objects</li>
<li>Tracing Errors</li>
<li>Trapping Errors</li>
<li>Reporting Errors</li>
</ul>
<p>Other great <a href="http://support.microsoft.com/kb/968929" target="_blank">PowerShell</a> Error Handling posts:</p>
<ul>
<li><a href="http://huddledmasses.org/trap-exception-in-powershell/">http://huddledmasses.org/trap-exception-in-powershell/</a></li>
<li><a href="http://blogs.msdn.com/powershell/archive/2006/11/03/erroraction-and-errorvariable.aspx">http://blogs.msdn.com/powershell/archive/2006/11/03/erroraction-and-errorvariable.aspx</a></li>
<li><a href="http://tfl09.blogspot.com/2009/01/error-handling-with-powershell.html">http://tfl09.blogspot.com/2009/01/error-handling-with-powershell.html</a></li>
<li><a href="http://weblogs.asp.net/adweigert/archive/2007/10/10/powershell-try-catch-finally-comes-to-life.aspx">http://weblogs.asp.net/adweigert/archive/2007/10/10/powershell-try-catch-finally-comes-to-life.aspx</a></li>
<li><a href="http://powershell.com/cs/blogs/ebook/archive/2009/03/30/chapter-11-finding-and-avoiding-errors.aspx">http://powershell.com/cs/blogs/ebook/archive/2009/03/30/chapter-11-finding-and-avoiding-errors.aspx</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.usepowershell.com/2009/07/deep-dive-error-handling-error-types-part-1/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PowerShell, VMWare, and VESI in Wisconsin</title>
		<link>http://blog.usepowershell.com/2009/04/powershell-vmware-and-vesi-in-wisconsin/</link>
		<comments>http://blog.usepowershell.com/2009/04/powershell-vmware-and-vesi-in-wisconsin/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 13:10:29 +0000</pubDate>
		<dc:creator>Steven Murawski</dc:creator>
				<category><![CDATA[Events]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell Community]]></category>
		<category><![CDATA[PowerShell Version 1]]></category>
		<category><![CDATA[VMWare]]></category>
		<category><![CDATA[Virtualization]]></category>

		<guid isPermaLink="false">http://blog.usepowershell.com/?p=120</guid>
		<description><![CDATA[On May 19th, Scott Herold and I will be presenting for the Wisconsin VMWare Users Group.  I&#8217;ll be covering the basics of PowerShell, as well as an introduction to the VI Toolkit (for Windows)/PowerCLI. Scott will be talking about  the Virtualization EcoShell Initiative (VESI). If you are in Wisconsin, the meeting details can be found here. [...]]]></description>
			<content:encoded><![CDATA[<p>On May 19th, <a href="http://www.vmguru.com/" target="_blank">Scott Herold</a> and I will be presenting for the Wisconsin VMWare Users Group. </p>
<p>I&#8217;ll be covering the basics of PowerShell, as well as an introduction to the VI Toolkit (for Windows)/PowerCLI.</p>
<p>Scott will be talking about  <a href="http://thevesi.org/index.jspa" target="_blank">the Virtualization EcoShell Initiative (VESI)</a>.</p>
<p>If you are in Wisconsin, the meeting details can be found <a href="http://campaign.vmware.com/usergroup/invites/Wisconsin_5-19-09.html" target="_blank">here</a>.</p>
<p>If you are not able to make the meeting, VMWare will be providing <a href="https://vmware.webex.com/vmware/j.php?ED=117340947&amp;UID=1109236007" target="_blank">a live stream of our presentations via WebEx</a>, as well as providing recordings after the fact.  </p>
<p>My presentation starts at 9 AM Central time and Scott follows me at about 9:50.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.usepowershell.com/2009/04/powershell-vmware-and-vesi-in-wisconsin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coming To A WSUS Server Near You &#8211;&gt; PowerShell V1.0</title>
		<link>http://blog.usepowershell.com/2009/03/coming-to-a-wsus-server-near-you-powershell-v10/</link>
		<comments>http://blog.usepowershell.com/2009/03/coming-to-a-wsus-server-near-you-powershell-v10/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 21:50:24 +0000</pubDate>
		<dc:creator>Steven Murawski</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell Version 1]]></category>

		<guid isPermaLink="false">http://blog.usepowershell.com/2009/03/coming-to-a-wsus-server-near-you-powershell-v10/</guid>
		<description><![CDATA[Richard Siddaway has just posted that PowerShell 1.0 is available as an optional update. I just checked my WSUS Server and there it is!!! Deployment is now a snap. More details in his blog post.. or in the MS Knowledge Base.]]></description>
			<content:encoded><![CDATA[<p><a href="http://richardsiddaway.spaces.live.com/default.aspx" target="_blank">Richard Siddaway</a> has <a href="http://richardsiddaway.spaces.live.com/Blog/cns!43CFA46A74CF3E96!2185.entry" target="_blank">just posted that PowerShell 1.0 is available as an optional update</a>.</p>
<p>I just checked my WSUS Server and there it is!!! Deployment is now a snap.</p>
<p><a href="http://richardsiddaway.spaces.live.com/Blog/cns!43CFA46A74CF3E96!2185.entry" target="_blank">More details in his blog post..</a> or in the <a href="http://support.microsoft.com/kb/926139" target="_blank">MS Knowledge Base</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.usepowershell.com/2009/03/coming-to-a-wsus-server-near-you-powershell-v10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tip: Passing Parameters Revisited</title>
		<link>http://blog.usepowershell.com/2009/03/tip-passing-parameters-revisited/</link>
		<comments>http://blog.usepowershell.com/2009/03/tip-passing-parameters-revisited/#comments</comments>
		<pubDate>Mon, 16 Mar 2009 12:22:57 +0000</pubDate>
		<dc:creator>Steven Murawski</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell Version 1]]></category>
		<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://blog.usepowershell.com/2009/03/tip-passing-parameters-revisited/</guid>
		<description><![CDATA[In Jeff Hicks’s Prof. PowerShell series, he continues with his tips on working with functions.  He uses the Check-Service function that was in the previous article and that I provided another option in this post.  Jeff describes how you can make a function act more like a cmdlet. The problem that you run into in [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://twitter.com/JeffHicks" target="_blank">Jeff Hicks</a>’s <a href="http://mcpmag.com/columns/columnist.asp?columnistsid=81" target="_blank">Prof. PowerShell series</a>, he continues with his <a href="http://mcpmag.com/columns/article.asp?editorialsid=3035" target="_blank">tips on working with functions</a>.  He uses the Check-Service function that was in the <a href="http://mcpmag.com/columns/article.asp?editorialsid=3028" target="_blank">previous article</a> and that I provided another option in <a href="http://blog.usepowershell.com/2009/03/tip-passing-parameters/" target="_blank">this post</a>.  Jeff describes how you can make a function act more like a cmdlet.</p>
<p>The problem that you run into in V1 of PoweShell is that it is easy to make your functions work with the pipeline</p>
<p><strong>Function Check-Service {<br />
  Param([string]$service=”spooler” )<br />
  PROCESS<br />
  {<br />
    $wmi=get-wmiobject win32_service -filter “name=’$service’” -computername $_ <br />
    if ($wmi.state -eq “running”)  {<br />
      write $True<br />
    }<br />
    else {<br />
      write $False<br />
    }<br />
  }<br />
}<br />
 <br />
Get-Content servers.txt | Check-Service</strong></p>
<p><em>OR</em> work well with parameters being passed in.</p>
<p><strong>Function Check-Service {<br />
  Param([string[]]$server=$env:computername, [string]$service=”spooler” ) <br />
    $wmi=get-wmiobject win32_service -filter “name=’$service’” -computername $server <br />
    if ($wmi.state -eq “running”)  {<br />
      write $True<br />
    }<br />
    else {<br />
      write $False<br />
    }<br />
} <br />
  <br />
Check-Service –Server Server01, Server02, Server03 </strong></p>
<p>Advanced functions in V2 of PowerShell can alleviate this problem (a topic for a whole new post), but a workaround I’ve found for V1 is to use the Begin block to take certain command line parameters and pass them back into the function via the pipeline.</p>
<p><strong>Function Check-Service {<br />
Param([string[]]$server=$null,[string]$service=”spooler” )<br />
  BEGIN<br />
  {<br />
    if ($server -ne $null)<br />
    {<br />
      $server | Check-Service –Service $service<br />
    }<br />
  }<br />
  PROCESS<br />
  {<br />
    if ($_ -ne $null)<br />
    {<br />
      $wmi=get-wmiobject win32_service -filter &#8220;name=&#8217;$service&#8217;&#8221; -computername $_<br />
      if ($wmi.state -eq “running”)  {<br />
        write $True<br />
      }<br />
      else {  write $False  }<br />
    }<br />
  }<br />
}</strong></p>
<p>This enables both of the above scenarios:</p>
<p>Get-Content servers.txt | Check-Service</p>
<p>Check-Service –Server Server01, Server02, Server03</p>
<p><a href="http://blogs.msdn.com/powershell/archive/2009/03/01/powershell-folksonomy.aspx" target="_blank">PSMDTAG</a>:FAQ param</p>
<p><a href="http://blogs.msdn.com/powershell/archive/2009/03/01/powershell-folksonomy.aspx" target="_blank">PSMDTAG</a>:FAQ pipeline</p>
<p><strong>Updated: (Missed a little recursion bug.. thanks Aleksandar!)</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.usepowershell.com/2009/03/tip-passing-parameters-revisited/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Tip: Passing Parameters</title>
		<link>http://blog.usepowershell.com/2009/03/tip-passing-parameters/</link>
		<comments>http://blog.usepowershell.com/2009/03/tip-passing-parameters/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 15:50:24 +0000</pubDate>
		<dc:creator>Steven Murawski</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell Version 1]]></category>
		<category><![CDATA[Tip]]></category>

		<guid isPermaLink="false">http://blog.usepowershell.com/2009/03/tip-passing-parameters/</guid>
		<description><![CDATA[Jeffery Hicks recently talked about the Param statement in his Prof. Powershell column for MCP Magazine (Keeping Your Options Open).  If you are new to PowerShell, I would definitely recommend reading the article, as provides a nice introduction to the Param statement.  Jeffrey recommended to cast your parameter as the type of object that you [...]]]></description>
			<content:encoded><![CDATA[<p>Jeffery Hicks <a href="http://mcpmag.com/columns/article.asp?editorialsid=3028" target="_blank">recently talked about the Param statement in his Prof. Powershell column for MCP Magazine</a> (Keeping Your Options Open).  If you are new to PowerShell, I would definitely recommend reading the article, as provides a nice introduction to the <strong>Param</strong> statement. </p>
<p>Jeffrey recommended to cast your parameter as the type of object that you are expecting, as way to catch errors.  I wholeheartedly agree.  That can cause trouble though, if you want to allow consumers of your script to pass in one or more values for that parameter.  In the spirit of the article’s title, I thought I would share a method I’ve come across to handle that situation.</p>
<p>Jeffrey gave is the below function.</p>
<p>Function Check-Service {<br />
  Param([string]$computername=$env:computername,<br />
    [string]$service=&#8221;spooler&#8221; )<br />
  $wmi=get-wmiobject win32_service -filter &#8220;name=&#8217;$service&#8217;&#8221; -computername $computername<br />
  if ($wmi.state -eq &#8220;running&#8221;)  {<br />
    write $True<br />
  }<br />
  else {<br />
    write $False<br />
  }<br />
}</p>
<p>Now, you can easily see where you might want to check for a service on multiple computers, but as this function stands, we would have to call it one time for each computer we want to check.</p>
<p>We can modify this script to take one or more computer names simply by changing the cast for the $computername variable from <strong>[string]</strong> to <strong>[string[]]</strong>.  That changes makes our variable hold an array of strings, rather than just one. </p>
<p>We don’t have to change the default value, as PowerShell handles the details of converting that value to an array. </p>
<p>Since the –ComputerName parameter for Get-WMIObject can take an array of computer names, we don’t have to change much else in the function. </p>
<p>I do add a foreach loop for the reporting end of the script, so we can see which machines have the service running.</p>
<p>And I end up with this (<strong>my changes in bold</strong>):</p>
<p>Function Check-Service</p>
<p>{</p>
<p>  Param( <strong>[string[]]$computername</strong>=$env:computername, [string]$service=&#8221;spooler&#8221; )</p>
<p>  $wmi=get-wmiobject win32_service -filter &#8220;name=&#8217;$service&#8217;&#8221; -computername $computername</p>
<p>  <strong>foreach ($one in $wmi)</strong></p>
<p><strong>  {</strong></p>
<p><strong>    if ($one.state -eq &#8220;running&#8221;) </strong></p>
<p><strong>    {</strong></p>
<p><strong>      write $one.SystemName,</strong> $true</p>
<p><strong>    }</strong></p>
<p><strong>    else </strong></p>
<p><strong>    {</strong></p>
<p><strong>      write $one.SystemName,</strong> $False</p>
<p><strong>    }</strong></p>
<p><strong>  }</strong></p>
<p>}</p>
<p> </p>
<p><a href="http://blogs.msdn.com/powershell/archive/2009/03/01/powershell-folksonomy.aspx" target="_blank">I almost forgot </a>- </p>
<p>PSMDTAG:FAQ param</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.usepowershell.com/2009/03/tip-passing-parameters/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How To Send E-Mail From PowerShell</title>
		<link>http://blog.usepowershell.com/2009/03/how-to-send-e-mail-from-powershell/</link>
		<comments>http://blog.usepowershell.com/2009/03/how-to-send-e-mail-from-powershell/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 15:30:00 +0000</pubDate>
		<dc:creator>Steven Murawski</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[Base Class Libraries]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell Version 1]]></category>

		<guid isPermaLink="false">http://blog.usepowershell.com/?p=60</guid>
		<description><![CDATA[In my Exploring the .NET Framework series, I introduced the System.Net.Mail.MailMessage class.&#160; Being able to create a MailMessage object is all well and good, but if you can’t send it, it’s really not helpful. To send an email from PowerShell using the .NET Framework, you can use the System.Net.Mail.SMTPClient class. First, you need to create [...]]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://blog.usepowershell.com/category/net-framework/introduction/" target="_blank">Exploring the .NET Framework series</a>, I introduced the <a href="http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.aspx#" target="_blank">System.Net.Mail.MailMessage</a> class.&#160; Being able to create a MailMessage object is all well and good, but if you can’t send it, it’s really not helpful.</p>
<p>To send an email from <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/download.mspx" target="_blank">PowerShell</a> using the .NET Framework, you can use the <a href="http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx#" target="_blank">System.Net.Mail.SMTPClient</a> class.</p>
<p>First, you need to create your MailMessage</p>
<p>PS C:\scripts\PowerShell&gt; $message = <a href="http://technet.microsoft.com/en-us/library/d203c4ab-2d57-4103-a04e-d7869d06931e" target="_blank">New-Object</a> System.Net.Mail.MailMessage –ArgumentList <a href="mailto:steve@usepowershell.com">steve@usepowershell.com</a>, <a href="mailto:nobody@adomain.com">nobody@adomain.com</a>, ‘This is a test’, ‘I’m going to send an email via PowerShell’</p>
<p>If you need to add an attachment, you can add one with the <a href="http://msdn.microsoft.com/en-us/library/system.net.mail.attachment.aspx" target="_blank">System.Net.Mail.Attachment</a> class.</p>
<p>To create the attachment, we’ll create an use an overload of the Attachment class that allows us to specify a filename and a MIME type (the MIME types are available in several enumerations:&#160; <a href="http://msdn.microsoft.com/en-us/library/system.net.mime.mediatypenames.application.aspx" target="_blank">System.Net.Mime.MediaTypeNames.Application</a>, <a href="http://msdn.microsoft.com/en-us/library/system.net.mime.mediatypenames.image.aspx" target="_blank">System.Net.Mime.MediaTypeNames.Image</a>, and <a href="http://msdn.microsoft.com/en-us/library/system.net.mime.mediatypenames.text.aspx" target="_blank">System.Net.Mime.MediaTypeNames.Text</a> – I’ve had a bit of trouble accessing those enumerations via PowerShell, but you can specify the name of the enumeration value in a string).</p>
<p>PS C:\scripts\PowerShell&gt; $attachment = <a href="http://technet.microsoft.com/en-us/library/d203c4ab-2d57-4103-a04e-d7869d06931e" target="_blank">New-Object</a> System.Net.Mail.Attachment –ArgumentList &#8216;c:\docs\test.xls’, ‘Application/Octet’</p>
<p>PS C:\scripts\PowerShell&gt; $message.Attachments.Add($attachment)</p>
<p>After we have our email and optional attachment, we’ll create the SMTP client and have it configured to use the SMTP server of our choice.</p>
<p>The constructor of the SMTPClient class that we will use is</p>
<p>SmtpClient(    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; String host,     <br />)</p>
<p>PS C:\scripts\PowerShell&gt; $smtp = New-Object System.Net.Mail.SMTPClient –ArgumentList 10.10.10.15</p>
<p>All that is left is sending our email..</p>
<p>PS C:\scripts\PowerShell&gt; $smtp.Send($message)</p>
<p>Have fun!</p>
<p>NOTE:</p>
<p>There is a shortcut to creating the MailMessage object like we did.. there is an overload of Send where you can pass in four strings (from, to, subject, and message).&#160; The SMTPClient handles the creation of the MailMessage in the background.</p>
<p>A faster method would be</p>
<p>PS C:\scripts\PowerShell&gt; $smtp = New-Object System.Net.Mail.SMTPClient –ArgumentList 10.10.10.15</p>
<p>PS C:\scripts\PowerShell&gt; $smtp.Send(‘<a href="mailto:steve@usepowershell.com">steve@usepowershell.com</a>’, ‘<a href="mailto:nobody@adomain.com">nobody@adomain.com</a>’, ‘This is a test’, ‘I’m going to send an email via PowerShell’)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.usepowershell.com/2009/03/how-to-send-e-mail-from-powershell/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Exploring the .NET Framework with PowerShell &#8211; Constructors (Part 3)</title>
		<link>http://blog.usepowershell.com/2009/03/exploring-the-net-framework-with-powershell-constructors-part-3/</link>
		<comments>http://blog.usepowershell.com/2009/03/exploring-the-net-framework-with-powershell-constructors-part-3/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 13:30:00 +0000</pubDate>
		<dc:creator>Steven Murawski</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[Base Class Libraries]]></category>
		<category><![CDATA[Introduction]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell Version 1]]></category>

		<guid isPermaLink="false">http://blog.usepowershell.com/?p=9</guid>
		<description><![CDATA[In part 2(a &#38; b) of this series, we talked about methods and looked at ways to view their overloads, or ways to call them.&#160; We also looked at the objects returned from a method call.&#160; In this post, we are going to explore a special kind of method called the constructor. A constructor is [...]]]></description>
			<content:encoded><![CDATA[<p>In part 2(<a href="http://blog.usepowershell.com/2009/02/exploring-the-net-framework-with-powershell-calling-a-method-part-2a/" target="_blank">a</a> &amp; <a href="http://blog.usepowershell.com/2009/02/exploring-the-net-framework-with-powershell-calling-a-method-part-2b/" target="_blank">b</a>) of this series, we talked about methods and looked at ways to view their overloads, or ways to call them.&#160; We also looked at the objects returned from a method call.&#160; In this post, we are going to explore a special kind of method called the constructor.</p>
<p>A constructor is a method whose job is to create the object that you want to work with.&#160; When I created the Ping object</p>
<p>PS C:\scripts\PowerShell&gt; $ping = New-Object System.Net.NetworkInformation.Ping</p>
<p>the <a href="http://technet.microsoft.com/en-us/library/d203c4ab-2d57-4103-a04e-d7869d06931e" target="_blank">New-Object</a> cmdlet calls the <a href="http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ping.ping.aspx" target="_blank">constructor for Ping</a>.</p>
<p>Like other methods, constructors can require parameters and can have multiple overloads.&#160; </p>
<p>Let’s look at <a href="http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.aspx#" target="_blank">System.Net.Mail.MailMessage</a>, which is a object that represents an email message.</p>
<p>The <a href="http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.mailmessage.aspx" target="_blank">MailMessage constructor</a> contains several overloads.&#160; The first method listed is MailMessage(), which is the default constructor.&#160; This method does not require any arguments and returns an empty MailMessage object.&#160; In <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/download.mspx" target="_blank">PowerShell</a>, we would call this method via <a href="http://technet.microsoft.com/en-us/library/d203c4ab-2d57-4103-a04e-d7869d06931e" target="_blank">New-Object</a>, just like with Ping class.</p>
<p>MailMessage()</p>
<p> PS C:\scripts\PowerShell&gt; $message = New-Object System.Net.Mail.MailMessage</p>
<p>The first overload requires two <a href="http://msdn.microsoft.com/en-us/library/system.net.mail.mailaddress.aspx" target="_blank">MailAddress</a> objects, the first of which is the “from” address and the second is the “to” address.&#160; </p>
<p>MailMessage(   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; MailAddress from,    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; MailAddress to,    <br />)</p>
<p>Creating an object in PowerShell from a constructor that requires parameters can be done in two ways.&#160; The first is to use the method call notation.</p>
<p> PS C:\scripts\PowerShell&gt; $message = New-Object System.Net.Mail.MailMessage($MailFrom, $MailTo)</p>
<p>The second is to use the ArgumentList parameter.</p>
<p> PS C:\scripts\PowerShell&gt; $message = New-Object System.Net.Mail.MailMessage –ArgumentList $MailFrom, $MailTo</p>
<p>If you happen to have <a href="http://msdn.microsoft.com/en-us/library/system.net.mail.mailaddress.aspx" target="_blank">MailAddress</a> objects floating around, this might work for you.&#160; A more common scenario would be to use the next overload, which takes two strings.</p>
<p>MailMessage(   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; String from,    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; String to,    <br />)</p>
<p>This overload requires two strings, one for the “to” and one for the “from” address.&#160; </p>
<p>The final overload for MailMessage is</p>
<p>MailMessage(   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; String from,    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; String to,    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; String subject,    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; String body,    <br />)</p>
<p>This overload allows you to pass in four strings and get back basic MailMessage object that is ready to be sent.</p>
<p>Wouldn’t it be great to have a function, where we could provide a type name and get a listing of all the constructors, right from the command line (not needing to go to the MSDN documentation every time).&#160; Jeffrey Snover has beaten me to the punch and provided a function to find the constructors, appropriately called <a href="http://blogs.msdn.com/powershell/archive/2008/09/01/get-constructor-fun.aspx" target="_blank">Get-Constructor</a>.&#160; Add that function to the your toolbox, and exploring the .NET Framework becomes a lot easier.</p>
<p>Next up, we’ll look at static methods.&#160; Static methods are methods that can be called without having to create a instance of an object.</p>
<p>One particular type of static method that we’ll dig in to is the factory method, which is another way to create instances of objects.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.usepowershell.com/2009/03/exploring-the-net-framework-with-powershell-constructors-part-3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Adding Custom Properties to Functions</title>
		<link>http://blog.usepowershell.com/2009/02/adding-custom-properties-to-functions/</link>
		<comments>http://blog.usepowershell.com/2009/02/adding-custom-properties-to-functions/#comments</comments>
		<pubDate>Sat, 14 Feb 2009 02:24:26 +0000</pubDate>
		<dc:creator>Steven Murawski</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell Version 1]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[adaptive type system]]></category>
		<category><![CDATA[ps1xml]]></category>
		<category><![CDATA[type data]]></category>

		<guid isPermaLink="false">http://blog.usepowershell.com/2009/02/adding-custom-properties-to-functions/</guid>
		<description><![CDATA[A question was asked on StackOverflow regarding how to add properties to a function, and then be able to retain that custom property when recalling that function from the function Provider.&#160;&#160; I’m not going to copy my answer here, but I do want to throw out a possible work around for this issue.&#160; (It has [...]]]></description>
			<content:encoded><![CDATA[<p>A q<a href="http://stackoverflow.com/questions/544804/powershell-how-do-you-add-a-property-to-a-function-object-on-the-psdrive-functio" target="_blank">uestion</a> was asked on <a href="http://stackoverflow.com/" target="_blank">StackOverflow</a> regarding how to add properties to a function, and then be able to retain that custom property when recalling that function from the function Provider.&#160;&#160; I’m not going to copy <a href="http://stackoverflow.com/questions/544804/powershell-how-do-you-add-a-property-to-a-function-object-on-the-psdrive-functio/546107#546107" target="_blank">my answer</a> here, but I do want to throw out a possible work around for this issue.&#160; </p>
<p>(It has been bugging me and I can’t really concentrate on my other tasks, so I need to get this out of the way.)</p>
<p>One suggestion I had was to create a type extension that had the property he was adding, but he was more interested in tagging specific functions, not all of them.</p>
<p>So, I’ve written a couple of little ScriptProperties to save and restore NoteProperties which have been added to FunctionInfo objects.&#160; I’ve added these to a PS1XML.</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span> &lt;?xml version=<span style="color: #006080">&quot;1.0&quot;</span> encoding=<span style="color: #006080">&quot;utf-8&quot;</span> ?&gt; </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> &lt;Types&gt; </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span>     &lt;Type&gt; </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span>         &lt;Name&gt;System.Management.Automation.FunctionInfo&lt;/Name&gt; </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   5:</span>         &lt;Members&gt; </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span>             &lt;ScriptMethod&gt; </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   7:</span>                 &lt;Name&gt;SaveMetadata&lt;/Name&gt; </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   8:</span>                 &lt;Script&gt; </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   9:</span> $DefaultProperties = <span style="color: #006080">'PSPath'</span>, <span style="color: #006080">'PSDrive'</span>, <span style="color: #006080">'PSProvider'</span>, <span style="color: #006080">'PSIsContainer'</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  10:</span> $SaveDirectory = Split-Path $profile</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  11:</span> $File = Join-Path $SaveDirectory <span style="color: #006080">&quot;$($this.Name).xml&quot;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  12:</span> $this.PSObject.Properties | Where-Object {$DefaultProperties -notcontains $_.Name -and $_.MemberType <span style="color: #cc6633">-like</span> <span style="color: #006080">'NoteProperty'</span>} | Export-Clixml -Path $file</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  13:</span>                 &lt;/Script&gt; </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  14:</span>             &lt;/ScriptMethod&gt;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  15:</span>             &lt;ScriptMethod&gt; </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  16:</span>                 &lt;Name&gt;LoadMetadata&lt;/Name&gt; </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  17:</span>                 &lt;Script&gt; </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  18:</span> $SaveDirectory = split-path $profile</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  19:</span> $PathToCustomProp = Join-Path $SaveDirectory <span style="color: #006080">&quot;$($this.name).xml&quot;</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  20:</span> <span style="color: #0000ff">if</span> (Test-Path $PathToCustomProp)</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  21:</span> {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  22:</span>     <span style="color: #0000ff">foreach</span> ($Property <span style="color: #0000ff">in</span> Import-Clixml -Path $PathToCustomProp)</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  23:</span>     {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  24:</span>         Add-Member -InputObject $this -MemberType NoteProperty -Name $Property.Name -Value $Property.Value</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  25:</span>     }</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  26:</span> }</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  27:</span>                 &lt;/Script&gt; </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  28:</span>             &lt;/ScriptMethod&gt; </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  29:</span>         &lt;/Members&gt; </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  30:</span>     &lt;/Type&gt; </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  31:</span> &lt;/Types&gt; </pre>
</p></div>
</div>
<p>After saving this file as a PS1XML file, you can call <a href="http://technet.microsoft.com/en-us/library/dd315362.aspx" target="_blank">Update-TypeData</a> –Prepend path\to\thefile.ps1xml, and every FunctionInfo object will have two script properties – SaveMetadata and LoadMetadata.&#160; As I’ve configured it, the data will be saved to the user’s profile directory and under a filename that matches the function name.&#160; So, you can add NoteProperties to your heart’s desire and save and recall them as needed.&#160; </p>
<p>I don’t have a direct application for this, and it can probably be cleaned up or done more efficiently, but I had to work through the problem.&#160; I’d love to hear your feedback!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.usepowershell.com/2009/02/adding-custom-properties-to-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Comparing Database Schemas</title>
		<link>http://blog.usepowershell.com/2009/02/comparing-database-schemas/</link>
		<comments>http://blog.usepowershell.com/2009/02/comparing-database-schemas/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 13:34:48 +0000</pubDate>
		<dc:creator>Steven Murawski</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell Version 1]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Systems Administration]]></category>

		<guid isPermaLink="false">http://blog.usepowershell.com/?p=43</guid>
		<description><![CDATA[I regularly am working with several versions of a database for an application that I manage (a live database, training database, test database, and previous version database).&#160; Occasionally, I need to know what the differences between the databases are, especially after our vendor updates my test environment or right after an update in my training [...]]]></description>
			<content:encoded><![CDATA[<p>I regularly am working with several versions of a database for an application that I manage (a live database, training database, test database, and previous version database).&#160; Occasionally, I need to know what the differences between the databases are, especially after our vendor updates my test environment or right after an update in my training or live environment.&#160; </p>
<p>Since I spend a good portion of my day in PowerShell, I wrapped some system table queries in a PowerShell script and use Compare-Object to find any differences in the tables and compare the column definitions as well.&#160; The queries targets only user tables. </p>
<p>Compare-DatabaseSchema.ps1 takes several parameters.</p>
<ul>
<li>SqlServerOne – SQL Server for the first database </li>
<li>FirstDatabase – Name of the first database for the comparison </li>
<li>SqlUsernameOne – SQL user name for the first database </li>
<li>SqlPasswordOne – SQL password for the first database </li>
<li>SqlServerTwo – SQL Server for the second database </li>
<li>SecondDatabase – Name of the second database for comparison </li>
<li>SqlUsernameTwo – SQL user name for the second database </li>
<li>SqlPasswordTwo – SQL password for the second database </li>
<li>FilePrefix – Prefix for the log file name </li>
<li>Log – Switch parameter that saves one CSV file with the difference in the tables.&#160; If the Column switch parameter is chosen also, it will save one CSV file per table with differences in the columns </li>
<li>Column – Switch parametr that enables a comparison of the columns in the tables that match.&#160; Columns are compared by name and datatype. </li>
</ul>
<p>I still have to add some checks for the various constraints, but that will come later.</p>
<p>You can find <a href="http://poshcode.org/865" target="_blank">the script</a> on <a href="http://poshcode.org/" target="_blank">PoShCode.org</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.usepowershell.com/2009/02/comparing-database-schemas/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Dealing with WMI Timeouts</title>
		<link>http://blog.usepowershell.com/2009/01/dealing-with-wmi-timeouts/</link>
		<comments>http://blog.usepowershell.com/2009/01/dealing-with-wmi-timeouts/#comments</comments>
		<pubDate>Mon, 26 Jan 2009 19:09:14 +0000</pubDate>
		<dc:creator>Steven Murawski</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell Version 1]]></category>
		<category><![CDATA[Systems Administration]]></category>
		<category><![CDATA[timeout]]></category>
		<category><![CDATA[wmi]]></category>

		<guid isPermaLink="false">http://blog.usepowershell.com/2009/01/dealing-with-wmi-timeouts/</guid>
		<description><![CDATA[There was a question in the PowerShellCommunity.Org forums about WMI timeouts. I did some digging and found there are several different types of timeouts that can affect your WMI queries.&#160; I’m still working through different scenarios and I’d appreciate any feedback. The first type of timeout can occur if the machine that you are targeting [...]]]></description>
			<content:encoded><![CDATA[<p>There was a <a href="http://powershellcommunity.org/Forums/tabid/54/aff/1/aft/3526/afv/topic/Default.aspx" target="_blank">question</a> in the <a href="http://powershellcommunity.org/" target="_blank">PowerShellCommunity.Org</a> forums about WMI timeouts.</p>
<p>I did some digging and found there are several different types of timeouts that can affect your WMI queries.&#160; I’m still working through different scenarios and I’d appreciate any feedback.</p>
<p>The first type of timeout can occur if the machine that you are targeting does not respond to network traffic (it’s down, you have the wrong IP address, firewalled, etc..).&#160; Your WMI call will usually time out after around 20 seconds.</p>
<p>A partial solution to that type of timeout is to ping the machine first.&#160; If you can ping that machine, you’ve eliminated a number of potential problems.&#160; You still might have permission issues or firewall issues, but you are able to reach the machine.</p>
<p>The second time of timeout I’ve seen is when the connection is made, but the WMI call hangs and does not return.</p>
<p>A potential fix for this issue is to use the [WMISearcher] accelerator.&#160; In the options property of the resulting object, there is a ReturnImmediately property, which should be set by default to true.</p>
<p>$searcher = [WMISearcher]&#8221;</p>
<p>$searcher.Options.ReturnImmediately</p>
<p>The ReturnImmediately property being set to true requires that the invoked operation (the search) be done synchronously and return immediately.&#160; The enumeration of the results of the WMI call are handled after the return of this operation.</p>
<p>An alternative solution for this issue would be to check the Transaction timeout setting on the target machine.&#160; Run DCOMCnfg.exe and navigate to the Component Services-&gt;My Computer.&#160; Right click and choose properties.&#160; On the options tab, there is a timeout (in seconds) for DCOM transactions.&#160; The default value for this setting is 60 seconds.&#160; Fiddle with that at your own risk.&#160; Also, I haven’t had a chance to check for where that value is in the registry or see if there is a Group Policy setting for it.&#160; Setting this value should allow a failed WMI connection to timeout more quickly.</p>
<p>The third area in which I’ve found timeouts/hangs in WMI queries is during the enumeration of the query results.&#160; There is a property in options for the WMI class accelerator called Timeout, which sets the length of time between enumerations before timing out.&#160; The options property is hidden in the default view of PowerShell, so you will need to access it via the psbase property.&#160; </p>
<p>The timeout value is a <a href="http://msdn.microsoft.com/en-us/library/system.timespan.aspx" target="_blank">System.TimeSpan</a> object.&#160; You can specify the value with a TimeSpan object, a number of ticks, or a string that can be cast to a TimeSpan.</p>
<p>It can be set like this:</p>
<p>$wmi = [wmi]&#8221;</p>
<p>$wmi.psbase.options.timeout =&#8217;0:0:2&#8242; #String that will be cast to a two second TimeSpan</p>
<p>You can also set a timeout value for the [WMISearcher] accelerator.</p>
<p>$searcher = [WMISearcher]&#8221;</p>
<p>$searcher.Options.timeout = &#8217;0:0:2&#8242;</p>
<p>WMI timeouts can be aggravating, hopefully one of these solutions will help mitigate your WMI woes. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.usepowershell.com/2009/01/dealing-with-wmi-timeouts/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
