<?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>MWJ Computing &#187; PowerShell</title>
	<atom:link href="http://www.mwjcomputing.com/blog/category/powershell/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mwjcomputing.com/blog</link>
	<description>A life lived through digital exploration.</description>
	<lastBuildDate>Mon, 02 Aug 2010 16:56:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Documenting PowerShell Scripts &#8211; Part 1</title>
		<link>http://www.mwjcomputing.com/blog/2010/08/documenting-powershell-scripts-part-1/</link>
		<comments>http://www.mwjcomputing.com/blog/2010/08/documenting-powershell-scripts-part-1/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 16:56:33 +0000</pubDate>
		<dc:creator>Matt Johnson</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Advanced Functions]]></category>
		<category><![CDATA[Documentation]]></category>
		<category><![CDATA[Help]]></category>

		<guid isPermaLink="false">http://www.mwjcomputing.com/blog/2010/08/documenting-powershell-scripts-part-1/</guid>
		<description><![CDATA[A “best practice” I follow is I document everything I do in a script. There are times I need to go back to a script years later and need to know exactly what it does. This is the first post in a series on how I document my scripts. Hopefully this helps you. The first [...]]]></description>
			<content:encoded><![CDATA[<p>A “best practice” I follow is I document everything I do in a script. There are times I need to go back to a script years later and need to know exactly what it does. This is the first post in a series on how I document my scripts. Hopefully this helps you.</p>
<p>The first topic we are going to cover is something called “Advanced Functions”. This topic has been covered many times before by other people. I wanted to put my spin on this.</p>
<p>When you use Advanced Functions you add the following line to the first line of your function or script.</p>
<pre><span style="color: #000000">[</span><span style="color: #0000ff">CmdletBinding</span><span style="color: #000000">()]</span></pre>
<p>This line, when used in Windows PowerShell 2.0 scripts or functions, gives you the following cmdlets among other things.</p>
<ul>
<li>Write-Verbose </li>
<li>Write-Debug </li>
</ul>
<p>How does this help me document you ask? </p>
<p>I use Write-Verbose for everything I am doing in a script and function. From assigning variables, changing values, switching in and out of functions, I document EVERYTHING. You can put anything you want in Write-Verbose.</p>
<p>One cool trick I do is the following where it gives you the name of the script you are running when you run it.</p>
<pre><span style="color: #5f9ea0">Write-Verbose</span><span style="color: #000000"> </span><span style="color: #5f9ea0">-Message</span><span style="color: #000000"> </span><span style="color: #800000">&quot;Running Script: $MyInvocation.MyCommand&quot;</span></pre>
<p>I also add things to my scripts and functions so that when other people run the script, they can see who wrote it and other information.</p>
<pre><span style="color: #5f9ea0">Write-Verbose</span><span style="color: #000000"> </span><span style="color: #5f9ea0">-Message</span><span style="color: #000000"> </span><span style="color: #800000">&quot;Running Script: $MyInvocation.MyCommand&quot;</span><span style="color: #000000">
</span><span style="color: #5f9ea0">Write-Verbose</span><span style="color: #000000"> </span><span style="color: #5f9ea0">-Message</span><span style="color: #000000"> </span><span style="color: #800000">&quot;Author: Matt Johnson - email@address&quot;</span><span style="color: #000000">
</span><span style="color: #5f9ea0">Write-Verbose</span><span style="color: #000000"> </span><span style="color: #5f9ea0">-Message</span><span style="color: #000000"> </span><span style="color: #800000">&quot;Script Version: 1.0&quot;</span><span style="color: #000000">
</span><span style="color: #5f9ea0">Write-Verbose</span><span style="color: #000000"> </span><span style="color: #5f9ea0">-Message</span><span style="color: #000000"> </span><span style="color: #800000">&quot;Join the SE Michigan PowerShell Script Club&quot;</span><span style="color: #000000">
</span><span style="color: #5f9ea0">Write-Verbose</span><span style="color: #000000"> </span><span style="color: #5f9ea0">-Message</span><span style="color: #000000"> </span><span style="color: #800000">&quot;http://www.michiganpowershell.com&quot;</span></pre>
<p>Now when you run your script or function –verbose you get the added information you placed in your script. The possibilities are endless.</p>
<p>I also use Write-Debug but not as frequently. I use those lines to go into further detail on what I am doing. Something that people running my scripts may not want to see if they want more info.</p>
<p>I encourage you to add the [CmdletBinding()] statement to your PowerShell 2.0 scripts and functions and play around with those two statements. </p>
<p>Up Next: Inline Help</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mwjcomputing.com/blog/2010/08/documenting-powershell-scripts-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>2010 Scripting Games Wrap Up</title>
		<link>http://www.mwjcomputing.com/blog/2010/05/2010-scripting-games-wrap-up/</link>
		<comments>http://www.mwjcomputing.com/blog/2010/05/2010-scripting-games-wrap-up/#comments</comments>
		<pubDate>Mon, 24 May 2010 21:27:18 +0000</pubDate>
		<dc:creator>Matt Johnson</dc:creator>
				<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://www.mwjcomputing.com/blog/2010/05/2010-scripting-games-wrap-up/</guid>
		<description><![CDATA[Well the expert answers are now being published over on the Hey Scripting Guys blog. So I figured I would write up a little on my experience during the games, how little they may be. I sent in only 3 scripts as life got in the way. Too much school and working. Oh well. I [...]]]></description>
			<content:encoded><![CDATA[<p>Well the expert answers are now being published over on the Hey Scripting Guys blog. So I figured I would write up a little on my experience during the games, how little they may be. </p>
<p>I sent in only 3 scripts as life got in the way. Too much school and working. Oh well. I did however complete 95% of each script but wasn’t happy with the code so I didn’t submit them. I know I should have submitted them anyways, but oh well. This however doesn’t mean I am done working on them. I plan on posting my solutions on my blog as I get time to finish them. (Probably sometime in June.)</p>
<p>The good thing is that I did learn some things and remember a few others. After all, isn’t that the whole reason for the Scripting Games anyways?</p>
<ol>
<li>The first thing I remembered is how cool Tee-Object is. For those of you who don’t know Tee-Object sends what you pass it to both the screen and a file. I am assuming this is based of the tee command in Unix. No matter where it is from, I am going to try to remember to add this to my bag of tricks. See my example below. I am running Get-Process and selecting the first 10. I am then passing that to Tee-Object and saving it to a file and viewing the content at the same time. Very Cool!      <br /><a href="http://www.mwjcomputing.com/blog/wp-content/uploads/2010/05/teeobject51910.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="tee-object-51910" border="0" alt="tee-object-51910" src="http://www.mwjcomputing.com/blog/wp-content/uploads/2010/05/teeobject51910_thumb.jpg" width="502" height="294" /></a>       </li>
<li>I learned I was making things to hard for myself. Before the Scripting Games I would use a parameter named DEBUG and an if statement to write extra information to the screen when running a script. Good news! PowerShell v2.0 has a statement you can add to your scripts to force your scripts to recognize the debug parameter. Once you add that you can use the Write-Debug cmdlet. This makes life so much easier. </li>
<li>I remembered that there are tons of different resources. Use them. I can’t stress that enough. Without those resources everything gets exponentially more difficult.</li>
</ol>
<p>There are also some thank you’s that need to go out.</p>
<ol>
<li>The Scripting Guys. I can’t even imagine how much work goes into producing an event like this. Thank you for doing this for the community.</li>
<li>Joel Bennett (Jaykul) for hosting PoshCode and the repository for posting our scripts.</li>
<li>The sponsors of the Scripting Games.      </li>
<ul>
<li><a href="http://bit.ly/2010sgteched">Tech·Ed 2010 North America</a></li>
<li><a href="http://bit.ly/2010sgsponsorposhcode">PoshCode.org</a></li>
<li><a href="http://bit.ly/2010sgsponsortechnet">Microsoft TechNet</a></li>
<li><a href="http://bit.ly/2010sgsponsorsapien">SAPIEN Technologies</a></li>
<li><a href="http://bit.ly/2010sgsponsorquest">Quest Software</a></li>
<li><a href="http://bit.ly/2010sgsponsornsoftware">/n software</a></li>
<li><a href="http://bit.ly/2010sgsponsorsoftwarefx">Software FX</a></li>
<li><a href="http://bit.ly/2010sgsponsor101">101FreeTechBooks.com</a></li>
<li><a href="http://bit.ly/2010sgsponsorshelltools">ShellTools</a></li>
<li><a href="http://bit.ly/2010sgsponsoridera">Idera</a></li>
</ul>
</ol>
<p>Lastly, I want to thank Ed personally for allowing me to write a solution for Advanced Event 4. I can say that has been the highlight of my scripting career.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mwjcomputing.com/blog/2010/05/2010-scripting-games-wrap-up/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>2010 Scripting Games Are Here!</title>
		<link>http://www.mwjcomputing.com/blog/2010/04/2010-scripting-games-are-here/</link>
		<comments>http://www.mwjcomputing.com/blog/2010/04/2010-scripting-games-are-here/#comments</comments>
		<pubDate>Mon, 26 Apr 2010 12:51:19 +0000</pubDate>
		<dc:creator>Matt Johnson</dc:creator>
				<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://www.mwjcomputing.com/blog/2010/04/2010-scripting-games-are-here/</guid>
		<description><![CDATA[The 2010 Scripting Games began this morning! You should head over to the Official 2010 Scripting Games Page and get started! Happy Scripting!]]></description>
			<content:encoded><![CDATA[<p>The 2010 Scripting Games began this morning! You should head over to the <a href="http://blogs.technet.com/heyscriptingguy/archive/2010/04/05/2010-scripting-games-all-links-on-one-page.aspx" target="_blank">Official 2010 Scripting Games Page</a> and get started!</p>
<p>Happy Scripting! </p>
]]></content:encoded>
			<wfw:commentRss>http://www.mwjcomputing.com/blog/2010/04/2010-scripting-games-are-here/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Function to check for valid IP</title>
		<link>http://www.mwjcomputing.com/blog/2010/04/function-to-check-for-valid-ip/</link>
		<comments>http://www.mwjcomputing.com/blog/2010/04/function-to-check-for-valid-ip/#comments</comments>
		<pubDate>Mon, 19 Apr 2010 17:33:53 +0000</pubDate>
		<dc:creator>Matt Johnson</dc:creator>
				<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://www.mwjcomputing.com/blog/2010/04/function-to-check-for-valid-ip/</guid>
		<description><![CDATA[Just thought I would share this. I needed to check to see if an IP was valid when going through an excel document. So I wrote a quick function to test to see if it is a valid IP address. You can download this function here. Quick and Simple! Enjoy! function Test-IsValidIP{ param ( [string]$ipAddress [...]]]></description>
			<content:encoded><![CDATA[<p>Just thought I would share this. I needed to check to see if an IP was valid when going through an excel document. So I wrote a quick function to test to see if it is a valid IP address.</p>
<p>You can download this function <a href="http://www.mwjcomputing.com/powershell/test-isvalidip.ps1" target="_blank">here</a>.</p>
<p>Quick and Simple! Enjoy!</p>
<pre><span style="color: #0000ff;">function</span><span style="color: #000000;"> </span><span style="color: #0000ff;">Test</span><span style="color: #ff0000;">-</span><span style="color: #0000ff;">IsValidIP</span><span style="color: #000000;">{
    </span><span style="color: #0000ff;">param</span><span style="color: #000000;"> (
        [</span><span style="color: #0000ff;">string</span><span style="color: #000000;">]</span><span style="color: #800080;">$ipAddress</span><span style="color: #000000;">
    )

    </span><span style="color: #008000;">#Regex Query
</span><span style="color: #000000;">    </span><span style="color: #800080;">$regexQuery</span><span style="color: #000000;"> </span><span style="color: #ff0000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">"^([1-9]|[1-9][0-9]|1[0-9][0-9]`
        |2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]`
        |1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$"</span><span style="color: #000000;">

    </span><span style="color: #0000ff;">if</span><span style="color: #000000;"> (</span><span style="color: #800080;">$ipAddress</span><span style="color: #000000;"> </span><span style="color: #ff0000;">-match</span><span style="color: #000000;"> </span><span style="color: #800080;">$regexQuery</span><span style="color: #000000;">){
        </span><span style="color: #0000ff;">return</span><span style="color: #000000;">(</span><span style="color: #0000ff;">$true</span><span style="color: #000000;">)
    } </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> {
        </span><span style="color: #0000ff;">return</span><span style="color: #000000;">(</span><span style="color: #0000ff;">$false</span><span style="color: #000000;">)
    }
}</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.mwjcomputing.com/blog/2010/04/function-to-check-for-valid-ip/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Are you competing in the Scripting Games? I am!</title>
		<link>http://www.mwjcomputing.com/blog/2010/04/are-you-competing-in-the-scripting-games-i-am/</link>
		<comments>http://www.mwjcomputing.com/blog/2010/04/are-you-competing-in-the-scripting-games-i-am/#comments</comments>
		<pubDate>Thu, 15 Apr 2010 19:21:23 +0000</pubDate>
		<dc:creator>Matt Johnson</dc:creator>
				<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://www.mwjcomputing.com/blog/2010/04/are-you-competing-in-the-scripting-games-i-am/</guid>
		<description><![CDATA[I am and let me explain why. The Scripting Games that are put on by the Microsoft Scripting Guys is a great opportunity to learn, advance or prove you know your stuff when it comes to scripting. I participated the last few times that the games were ran and I loved it. Every minute of [...]]]></description>
			<content:encoded><![CDATA[<p>I am and let me explain why. The Scripting Games that are put on by the Microsoft Scripting Guys is a great opportunity to learn, advance or prove you know your stuff when it comes to scripting. I participated the last few times that the games were ran and I loved it. Every minute of it. </p>
<p>The scripting games start on April 26th and go to May 7th. I know I am encouraging everyone in the <a href="http://michiganpowershell.com/" target="_blank">SE Michigan PowerShell Script</a> club to participate and hopefully you do to!</p>
<p>There are 10 events in both an beginner and advanced categories. This year there are two languages that the scripts can be written in. Those are PowerShell and VBScript. (I heard that this is the last year for VBScript. Boohoo! VBScript will always have a place in my heart but change is good. And besides PowerShell is awesome!) These events encompass tasks that can help you with your day to day job. Looking at the 2010 Scripting Games Study guide gives us a hint at what the events might entail. From working with text files and folders to using WMI information I am sure that everyone will find this to be fun and challenging. </p>
<p>When you are done writing your script, you can post it up along with everyone else's submission on the special Scripting Games section of the <a href="http://poshcode.org" target="_blank">PoshCode.org</a> website. That site is at <a href="http://2010sg.poshcode.org">http://2010sg.poshcode.org</a>. Very cool of PoshCode to do this if I do say so.</p>
<p>At the end of each event scripting experts will provide commentary on how they tackled the script and their solution. This is a great opportunity to learn from some of the best in the scripting community. You should note however that there are almost always many ways to solve a problem, but what some of the experts do is amazing in how well their scripts are written. </p>
<p>So with all that being said, I urge you to compete. Oh I forgot to mention there will be prizes? According to the FAQ they will be having 11 drawings, which amounts to one drawing per day and a grand prize. All you have to do to be eligible is to submit a script for the event! Now how easy is that? And who doesn’t love prizes? I know I do.</p>
<p>What do you do next? Well there are a few things you can do to get prepared.</p>
<ol>
<li>Register to compete! You can do this by going to <a href="http://2010sg.poshcode.org">http://2010sg.poshcode.org</a>. Make sure you do this so you can hit the round running on April 26th, 2010.</li>
<li>Read the Frequently Asked Questions. You can find them at <a href="http://bit.ly/2010sgdetails">http://bit.ly/2010sgdetails</a></li>
<li>Use the study guide the Scripting Guys so graciously provided at <a href="http://bitl.ly/2010sgstudyguide">http://bitl.ly/2010sgstudyguide</a>.</li>
<li>Read the Scripting Guys Blog and follow along as the Scripting Wife learns PowerShell! Their blog is at <a title="http://blogs.technet.com/heyscriptingguy/default.aspx" href="http://blogs.technet.com/heyscriptingguy/default.aspx">http://blogs.technet.com/heyscriptingguy/default.aspx</a></li>
<li>If you have your own website or blog, put the 2010 Scripting Games badge on your site so that everyone knows you are competing and you can help bring in more people! You can get that at <a href="http://bit.ly/2010sggrabbadge">http://bit.ly/2010sggrabbadge</a>. </li>
<li>If you use twitter or Facebook, make sure you add the Twibbon for your profile picture! You can get the twibbon at <a title="http://twibbon.com/join/2010-scripting-games" href="http://twibbon.com/join/2010-scripting-games">http://twibbon.com/join/2010-scripting-games</a>. </li>
</ol>
<p>I hope to see you on the “Scripting Field”.</p>
<p>Happy Scripting!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mwjcomputing.com/blog/2010/04/are-you-competing-in-the-scripting-games-i-am/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Validate time with a format of hh:mm:ss using RegEx</title>
		<link>http://www.mwjcomputing.com/blog/2010/04/validate-time-with-a-format-of-hhmmss-using-regex/</link>
		<comments>http://www.mwjcomputing.com/blog/2010/04/validate-time-with-a-format-of-hhmmss-using-regex/#comments</comments>
		<pubDate>Tue, 13 Apr 2010 17:36:52 +0000</pubDate>
		<dc:creator>Matt Johnson</dc:creator>
				<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://www.mwjcomputing.com/blog/2010/04/validate-time-with-a-format-of-hhmmss-using-regex/</guid>
		<description><![CDATA[Here are two quick ways to validate an entered date. Both examples work with PowerShell 2.0 but only the first one works with PowerShell 1.0. The following is a RegEx string to validate input in the format of hh:mm:ss. [01][0-9]:[0-6][0-9]:[0-6][0-9] We can use a simple if statement to validate the time as seen below $time [...]]]></description>
			<content:encoded><![CDATA[<p>Here are two quick ways to validate an entered date. Both examples work with PowerShell 2.0 but only the first one works with PowerShell 1.0.</p>
<p>The following is a RegEx string to validate input in the format of hh:mm:ss.</p>
<p>[01][0-9]:[0-6][0-9]:[0-6][0-9]</p>
<p>We can use a simple if statement to validate the time as seen below</p>
<pre><span style="color: #800080">$time</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800000">&quot;22:33:22&quot;</span><span style="color: #000000">

</span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$time</span><span style="color: #000000"> </span><span style="color: #ff0000">-match</span><span style="color: #000000"> </span><span style="color: #800000">&quot;[01][0-9]:[0-6][0-9]:[0-6][0-9]&quot;</span><span style="color: #000000">){
    </span><span style="color: #5f9ea0">Write-Host</span><span style="color: #000000"> </span><span style="color: #0000ff">$true</span><span style="color: #000000">
} </span><span style="color: #0000ff">else</span><span style="color: #000000">{
    </span><span style="color: #5f9ea0">Write-Host</span><span style="color: #000000"> </span><span style="color: #0000ff">$false</span><span style="color: #000000">
}</span></pre>
<p>Pat Richard pointed out that we can do this with a few less lines of code, so you can choose what way you want to do this. He used the –match switch against the variable itself. Here is what he suggested:</p>
<pre><span style="color: #800080">$time</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800000">&quot;22:33:22&quot;</span><span style="color: #000000">
</span><span style="color: #800080">$time</span><span style="color: #000000"> </span><span style="color: #ff0000">-match</span><span style="color: #000000"> </span><span style="color: #800000">&quot;[01][0-9]:[0-6][0-9]:[0-6][0-9]&quot;</span></pre>
<p>With PowerShell 2.0, we can validate it when it is entered as a parameter by adding the following lines into your param() statement replacing the variable $userTime with the name of your variable.</p>
<pre><span style="color: #000000">[</span><span style="color: #0000ff">ValidatePattern</span><span style="color: #000000">(</span><span style="color: #800000">&quot;[01][0-9]:[0-6][0-9]:[0-6][0-9]&quot;</span><span style="color: #000000">)]
[</span><span style="color: #0000ff">string</span><span style="color: #000000">]</span><span style="color: #800080">$userTime</span></pre>
<p>The following function validates time in the format of hh:mm:ss. It can also be downloaded <a href="http://www.mwjcomputing.com/powershell/test-isvalidtime.ps1" target="_blank">here</a>.</p>
<pre><span style="color: #0000ff">function</span><span style="color: #000000"> </span><span style="color: #5f9ea0">Test-IsValidTime</span><span style="color: #000000"> {
    </span><span style="color: #008000">&lt;#
    .</span><span style="color: #008000">SYNOPSIS</span><span style="color: #008000">
        </span><span style="color: #008000">Checks</span><span style="color: #008000"> </span><span style="color: #008000">to</span><span style="color: #008000"> </span><span style="color: #008000">see</span><span style="color: #008000"> </span><span style="color: #008000">if</span><span style="color: #008000"> </span><span style="color: #008000">value</span><span style="color: #008000"> </span><span style="color: #008000">entered</span><span style="color: #008000"> </span><span style="color: #008000">is</span><span style="color: #008000"> </span><span style="color: #008000">in</span><span style="color: #008000"> </span><span style="color: #008000">valid</span><span style="color: #008000"> </span><span style="color: #008000">format</span><span style="color: #008000">.

    .</span><span style="color: #008000">DESCRIPTION</span><span style="color: #008000">
        </span><span style="color: #008000">This</span><span style="color: #008000"> </span><span style="color: #008000">function</span><span style="color: #008000"> </span><span style="color: #008000">tests</span><span style="color: #008000"> </span><span style="color: #008000">to</span><span style="color: #008000"> </span><span style="color: #008000">see</span><span style="color: #008000"> </span><span style="color: #008000">if</span><span style="color: #008000"> </span><span style="color: #008000">the</span><span style="color: #008000"> </span><span style="color: #008000">date</span><span style="color: #008000"> </span><span style="color: #008000">entered</span><span style="color: #008000"> </span><span style="color: #008000">in</span><span style="color: #008000"> </span><span style="color: #008000">hh</span><span style="color: #008000">:</span><span style="color: #008000">mm</span><span style="color: #008000">:</span><span style="color: #008000">ss</span><span style="color: #008000"> </span><span style="color: #008000">format</span><span style="color: #008000"> </span><span style="color: #008000">is</span><span style="color: #008000"> </span><span style="color: #008000">a</span><span style="color: #008000"> </span><span style="color: #008000">valid</span><span style="color: #008000"> </span><span style="color: #008000">time</span><span style="color: #008000">.

    .</span><span style="color: #008000">PARAMETER</span><span style="color: #008000">  </span><span style="color: #008000">time</span><span style="color: #008000">
        </span><span style="color: #008000">Time</span><span style="color: #008000"> </span><span style="color: #008000">entered</span><span style="color: #008000"> </span><span style="color: #008000">in</span><span style="color: #008000"> </span><span style="color: #008000">format</span><span style="color: #008000"> </span><span style="color: #008000">of</span><span style="color: #008000"> </span><span style="color: #008000">hh</span><span style="color: #008000">:</span><span style="color: #008000">mm</span><span style="color: #008000">:</span><span style="color: #008000">ss</span><span style="color: #008000">.

    .</span><span style="color: #008000">EXAMPLE</span><span style="color: #008000">
        </span><span style="color: #008000">PS</span><span style="color: #008000"> </span><span style="color: #008000">C</span><span style="color: #008000">:\&gt; </span><span style="color: #008000">Test</span><span style="color: #008000">-</span><span style="color: #008000">IsValidTime</span><span style="color: #008000"> -</span><span style="color: #008000">time</span><span style="color: #008000"> '</span><span style="color: #008000">12</span><span style="color: #008000">:</span><span style="color: #008000">34</span><span style="color: #008000">:</span><span style="color: #008000">56</span><span style="color: #008000">'

    .</span><span style="color: #008000">INPUTS</span><span style="color: #008000">
        </span><span style="color: #008000">System</span><span style="color: #008000">.</span><span style="color: #008000">String</span><span style="color: #008000">

    .</span><span style="color: #008000">OUTPUTS</span><span style="color: #008000">
        </span><span style="color: #008000">System</span><span style="color: #008000">.</span><span style="color: #008000">Boolean</span><span style="color: #008000">

    .</span><span style="color: #008000">NOTES</span><span style="color: #008000">
        </span><span style="color: #008000">This</span><span style="color: #008000"> </span><span style="color: #008000">function</span><span style="color: #008000"> </span><span style="color: #008000">was</span><span style="color: #008000"> </span><span style="color: #008000">written</span><span style="color: #008000"> </span><span style="color: #008000">by</span><span style="color: #008000"> </span><span style="color: #008000">Matt</span><span style="color: #008000"> </span><span style="color: #008000">Johnson</span><span style="color: #008000"> </span><span style="color: #008000">of</span><span style="color: #008000"> </span><span style="color: #008000">the</span><span style="color: #008000"> </span><span style="color: #008000">SE</span><span style="color: #008000"> </span><span style="color: #008000">Michigan</span><span style="color: #008000"> </span><span style="color: #008000">PowerShell</span><span style="color: #008000"> </span><span style="color: #008000">Script</span><span style="color: #008000"> </span><span style="color: #008000">Club</span><span style="color: #008000">.

    .</span><span style="color: #008000">LINK</span><span style="color: #008000">
        </span><span style="color: #008000">http</span><span style="color: #008000">://</span><span style="color: #008000">www</span><span style="color: #008000">.</span><span style="color: #008000">mwjcomputing</span><span style="color: #008000">.</span><span style="color: #008000">com</span><span style="color: #008000">/</span><span style="color: #008000">blog</span><span style="color: #008000">/

    .</span><span style="color: #008000">LINK</span><span style="color: #008000">
        </span><span style="color: #008000">http</span><span style="color: #008000">://</span><span style="color: #008000">www</span><span style="color: #008000">.</span><span style="color: #008000">michiganpowershell</span><span style="color: #008000">.</span><span style="color: #008000">com</span><span style="color: #008000">/

    #&gt;</span><span style="color: #000000">

    </span><span style="color: #0000ff">param</span><span style="color: #000000"> (
    [</span><span style="color: #0000ff">string</span><span style="color: #000000">]</span><span style="color: #800080">$time</span><span style="color: #000000">
    )

    </span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$time</span><span style="color: #000000"> </span><span style="color: #ff0000">-match</span><span style="color: #000000"> </span><span style="color: #800000">&quot;[01][0-9]:[0-6][0-9]:[0-6][0-9]&quot;</span><span style="color: #000000">){
        </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">$true</span><span style="color: #000000">
    } </span><span style="color: #0000ff">else</span><span style="color: #000000">{
        </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">$false</span><span style="color: #000000">
    }

} </span><span style="color: #008000">#End Function Test-IsValidTime</span></pre>
<p>&#160;</p>
<p>Happy Scripting!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mwjcomputing.com/blog/2010/04/validate-time-with-a-format-of-hhmmss-using-regex/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Script to modify window for PowerShell demo</title>
		<link>http://www.mwjcomputing.com/blog/2010/04/script-to-modify-window-for-powershell-demo/</link>
		<comments>http://www.mwjcomputing.com/blog/2010/04/script-to-modify-window-for-powershell-demo/#comments</comments>
		<pubDate>Tue, 13 Apr 2010 15:31:20 +0000</pubDate>
		<dc:creator>Matt Johnson</dc:creator>
				<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://www.mwjcomputing.com/blog/2010/04/script-to-modify-window-for-powershell-demo/</guid>
		<description><![CDATA[When I do PowerShell demos, I want my screen to have some default characteristics. The script below is the one I started using when I do a PowerShell demo for co-workers, friends or the SE Michigan PowerShell Script Club. Feel free to tailor it to your liking! You can download this script here. Happy Scripting! [...]]]></description>
			<content:encoded><![CDATA[<p>When I do PowerShell demos, I want my screen to have some default characteristics. The script below is the one I started using when I do a PowerShell demo for co-workers, friends or the <a href="http://www.michiganpowershell.com/" target="_blank">SE Michigan PowerShell Script Club</a>. Feel free to tailor it to your liking! </p>
<p>You can download this script <a href="http://www.mwjcomputing.com/powershell/set-powershelldemo.ps1" target="_blank">here</a>.</p>
<p>Happy Scripting!</p>
<pre><span style="color: #008000">######################################################
# Script Name: set-powershelldemo.ps1
# Written By: Matt Johnson - powershell@mwjcomputing.com
# Revision Date: 4/12/2010
# Version: 2.0
# Version History:
#  - 1.0: Inital Script
#  - 2.0: Added host info switch and display
# Description: This script sets the window for the demo.
# Command Line: ./set-powershelldemo.ps1
# Example 1: ./set-powershelldemo.ps1
# Example 2: ./set-powershelldemo.ps1 -displayHost
######################################################
</span><span style="color: #0000ff">param</span><span style="color: #000000">(
    [</span><span style="color: #0000ff">switch</span><span style="color: #000000">]</span><span style="color: #800080">$displayHost</span><span style="color: #000000">
)

</span><span style="color: #008000"># Get UserInterface Object
</span><span style="color: #800080">$userInterface</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> (</span><span style="color: #5f9ea0">Get-Host</span><span style="color: #000000">)</span><span style="color: #000000">.</span><span style="color: #8b4513">UI</span><span style="color: #000000">.</span><span style="color: #8b4513">RawUI</span><span style="color: #000000">

</span><span style="color: #008000"># Set Window Title
</span><span style="color: #800080">$userInterface</span><span style="color: #000000">.</span><span style="color: #8b4513">WindowTitle</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800000">&quot;MWJ Computing PowerShell Demo&quot;</span><span style="color: #000000">

</span><span style="color: #008000"># Set Window Size
</span><span style="color: #800080">$windowSize</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$userInterface</span><span style="color: #000000">.</span><span style="color: #8b4513">WindowSize</span><span style="color: #000000">
</span><span style="color: #800080">$windowSize</span><span style="color: #000000">.</span><span style="color: #8b4513">Width</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #000000">120</span><span style="color: #000000">
</span><span style="color: #800080">$windowSize</span><span style="color: #000000">.</span><span style="color: #8b4513">Height</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #000000">50</span><span style="color: #000000">
</span><span style="color: #800080">$userInterface</span><span style="color: #000000">.</span><span style="color: #8b4513">WindowSize</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$windowSize</span><span style="color: #000000">

</span><span style="color: #008000"># Check for admin script
</span><span style="color: #800080">$wid</span><span style="color: #ff0000">=</span><span style="color: #000000">[</span><span style="color: #8b4513">System.Security.Principal.WindowsIdentity</span><span style="color: #000000">]</span><span style="color: #000000">::</span><span style="color: #8b4513">GetCurrent</span><span style="color: #000000">()
</span><span style="color: #800080">$prp</span><span style="color: #ff0000">=</span><span style="color: #5f9ea0">new-object</span><span style="color: #000000"> </span><span style="color: #8b4513">System.Security.Principal.WindowsPrincipal</span><span style="color: #000000">(</span><span style="color: #800080">$wid</span><span style="color: #000000">)
</span><span style="color: #800080">$adm</span><span style="color: #ff0000">=</span><span style="color: #000000">[</span><span style="color: #8b4513">System.Security.Principal.WindowsBuiltInRole</span><span style="color: #000000">]</span><span style="color: #000000">::</span><span style="color: #8b4513">Administrator</span><span style="color: #000000">
</span><span style="color: #800080">$IsAdmin</span><span style="color: #ff0000">=</span><span style="color: #800080">$prp</span><span style="color: #000000">.</span><span style="color: #8b4513">IsInRole</span><span style="color: #000000">(</span><span style="color: #800080">$adm</span><span style="color: #000000">)

</span><span style="color: #008000"># Check to see if admin, if is change background to red.
</span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$IsAdmin</span><span style="color: #000000">){
    (</span><span style="color: #5f9ea0">get-host</span><span style="color: #000000">)</span><span style="color: #000000">.</span><span style="color: #8b4513">UI</span><span style="color: #000000">.</span><span style="color: #8b4513">RawUI</span><span style="color: #000000">.</span><span style="color: #0000ff">Backgroundcolor</span><span style="color: #ff0000">=</span><span style="color: #800000">&quot;DarkRed&quot;</span><span style="color: #000000">
}

</span><span style="color: #008000"># Set Location to c:\fso
</span><span style="color: #5f9ea0">Set-Location</span><span style="color: #000000"> </span><span style="color: #5f9ea0">-path</span><span style="color: #000000"> </span><span style="color: #800000">'</span><span style="color: #008000; text-decoration: underline">C:\fso</span><span style="color: #800000">'</span><span style="color: #000000">

</span><span style="color: #008000"># Clear Screen
</span><span style="color: #0000ff">Clear</span><span style="color: #000000">

</span><span style="color: #008000"># Display Welcome Message
</span><span style="color: #5f9ea0">Write-Host</span><span style="color: #000000"> </span><span style="color: #5f9ea0">-object</span><span style="color: #000000"> </span><span style="color: #800000">&quot;Welcome to the MWJ Computing PowerShell Demo.&quot;</span><span style="color: #5f9ea0">`</span><span style="color: #000000">
    </span><span style="color: #5f9ea0">-foregroundcolor</span><span style="color: #000000"> </span><span style="color: #0000ff">Yellow</span><span style="color: #000000">
</span><span style="color: #5f9ea0">Write-Host</span><span style="color: #000000"> </span><span style="color: #5f9ea0">-object</span><span style="color: #000000"> </span><span style="color: #5f9ea0">`</span><span style="color: #000000">
    </span><span style="color: #800000">&quot;For more information, please visit http://www.mwjcomputing.com/blog/.&quot;</span><span style="color: #000000"> </span><span style="color: #5f9ea0">`</span><span style="color: #000000">
    </span><span style="color: #5f9ea0">-foregroundcolor</span><span style="color: #000000"> </span><span style="color: #0000ff">Yellow</span><span style="color: #000000">
</span><span style="color: #5f9ea0">Write-Host</span><span style="color: #000000"> </span><span style="color: #5f9ea0">-object</span><span style="color: #000000"> </span><span style="color: #800000">&quot;Happy Scripting!&quot;</span><span style="color: #000000"> </span><span style="color: #5f9ea0">-foregroundcolor</span><span style="color: #000000"> </span><span style="color: #0000ff">Yellow</span><span style="color: #000000">

</span><span style="color: #008000"># Check for DiplayHost switch.
</span><span style="color: #0000ff">if</span><span style="color: #000000"> (</span><span style="color: #800080">$displayHost</span><span style="color: #000000">){
    </span><span style="color: #5f9ea0">Write-Host</span><span style="color: #000000"> </span><span style="color: #5f9ea0">-object</span><span style="color: #000000"> </span><span style="color: #800000">&quot;&quot;</span><span style="color: #000000">
    </span><span style="color: #5f9ea0">Write-Host</span><span style="color: #000000"> </span><span style="color: #5f9ea0">-object</span><span style="color: #000000"> </span><span style="color: #800000">&quot;UserName: $env:USERNAME&quot;</span><span style="color: #000000"> </span><span style="color: #5f9ea0">`</span><span style="color: #000000">
        </span><span style="color: #5f9ea0">-foregroundcolor</span><span style="color: #000000"> </span><span style="color: #0000ff">Yellow</span><span style="color: #000000">
    </span><span style="color: #5f9ea0">Write-Host</span><span style="color: #000000"> </span><span style="color: #5f9ea0">-object</span><span style="color: #000000"> </span><span style="color: #800000">&quot;HostName: $env:COMPUTERNAME&quot;</span><span style="color: #000000"> </span><span style="color: #000000">1</span><span style="color: #000000">
        </span><span style="color: #5f9ea0">-foregroundcolor</span><span style="color: #000000"> </span><span style="color: #0000ff">Yellow</span><span style="color: #000000">
    </span><span style="color: #5f9ea0">Write-Host</span><span style="color: #000000"> </span><span style="color: #5f9ea0">-object</span><span style="color: #000000"> </span><span style="color: #800000">&quot;DomainName: $env:USERDNSDOMAIN&quot;</span><span style="color: #000000"> </span><span style="color: #000000">1</span><span style="color: #000000">
        </span><span style="color: #5f9ea0">-foregroundcolor</span><span style="color: #000000"> </span><span style="color: #0000ff">Yellow</span><span style="color: #000000">
    </span><span style="color: #5f9ea0">Write-Host</span><span style="color: #000000"> </span><span style="color: #5f9ea0">-object</span><span style="color: #000000"> </span><span style="color: #800000">&quot;Date: $(Get-Date)&quot;</span><span style="color: #000000"> </span><span style="color: #5f9ea0">-foregroundcolor</span><span style="color: #000000"> </span><span style="color: #0000ff">Yellow</span><span style="color: #000000">
    </span><span style="color: #5f9ea0">Write-Host</span><span style="color: #000000"> </span><span style="color: #5f9ea0">-object</span><span style="color: #000000"> </span><span style="color: #800000">&quot;Execution Policy: $(Get-ExecutionPolicy)&quot;</span><span style="color: #000000"> </span><span style="color: #5f9ea0">`</span><span style="color: #000000">
        </span><span style="color: #5f9ea0">-foregroundcolor</span><span style="color: #000000"> </span><span style="color: #0000ff">Yellow</span><span style="color: #000000">
}
 </span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.mwjcomputing.com/blog/2010/04/script-to-modify-window-for-powershell-demo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Need a certain PowerShell SnapIn? Make it required!</title>
		<link>http://www.mwjcomputing.com/blog/2010/04/need-a-certain-powershell-snapin-make-it-required/</link>
		<comments>http://www.mwjcomputing.com/blog/2010/04/need-a-certain-powershell-snapin-make-it-required/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 15:26:36 +0000</pubDate>
		<dc:creator>Matt Johnson</dc:creator>
				<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://www.mwjcomputing.com/blog/2010/04/need-a-certain-powershell-snapin-make-it-required/</guid>
		<description><![CDATA[I started doing this on all my scripts that require something like the Quest Active Directory SnapIns. It is quick and simple and when the script runs it checks for it and displays a message indicating you are missing a requirement. Pretty cool if you ask me. To require a SnapIn add the following line [...]]]></description>
			<content:encoded><![CDATA[<p>I started doing this on all my scripts that require something like the Quest Active Directory SnapIns. It is quick and simple and when the script runs it checks for it and displays a message indicating you are missing a requirement. Pretty cool if you ask me.</p>
<p>To require a SnapIn add the following line in the beginning of your script but replace it with the name of the SnapIn:</p>
<p><span style="color: #008000">#Requires -pssnapin name_of_snapin</span></p>
<p>As an example, lets say you want to require <a href="http://www.quest.com/powershell/activeroles-server.aspx" target="_blank">Quest’s Active Directory SnapIn</a>. You would add the following line in the beginning of your script</p>
<p><span style="color: #008000">#Requires -pssnapin Quest.ActiveRoles.ADManagement</span></p>
<p>If you don’t have the snapin loaded, you will get an error like the one below. </p>
<p><a href="http://www.mwjcomputing.com/blog/wp-content/uploads/2010/04/snapinrequires.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="snapin-requires" border="0" alt="snapin-requires" src="http://www.mwjcomputing.com/blog/wp-content/uploads/2010/04/snapinrequires_thumb.png" width="545" height="117" /></a> </p>
<p>This is a nice feature and hopefully you all start using it!</p>
<p>Happy Scripting!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mwjcomputing.com/blog/2010/04/need-a-certain-powershell-snapin-make-it-required/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell Script &#8211; Get-DiskOffset.ps1</title>
		<link>http://www.mwjcomputing.com/blog/2010/03/powershell-script-get-diskoffset-ps1/</link>
		<comments>http://www.mwjcomputing.com/blog/2010/03/powershell-script-get-diskoffset-ps1/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 20:12:31 +0000</pubDate>
		<dc:creator>Matt Johnson</dc:creator>
				<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://www.mwjcomputing.com/blog/2010/03/powershell-script-get-diskoffset-ps1/</guid>
		<description><![CDATA[###################################################### # Script Name: get-diskoffset.ps1 # Written By: Matt Johnson - powershell [at] mwjcomputing.com # Revision Date: 3/25/2010 # Version: 1.0 # Version History: # - 1.0: Initial Script # Description: This script displays the disk offset info. # Command Line: ./get-serverspace.ps1 # Example: ./get-diskoffset.ps1 MAGNET # Example: ./get-diskoffset.ps1 # Notes: # - Based on [...]]]></description>
			<content:encoded><![CDATA[<pre><span style="color: #008000">######################################################
# Script Name: get-diskoffset.ps1
# Written By: Matt Johnson - powershell [at] mwjcomputing.com
# Revision Date: 3/25/2010
# Version: 1.0
# Version History:
#  - 1.0: Initial Script
# Description: This script displays the disk offset info.
# Command Line: ./get-serverspace.ps1
# Example: ./get-diskoffset.ps1 MAGNET
# Example: ./get-diskoffset.ps1
# Notes:
# - Based on script located at </span><span style="color: #008000; text-decoration: underline">http://braunblog.com/?p=32</span><span style="color: #008000">
######################################################
</span><span style="color: #000000">
</span><span style="color: #0000ff">param</span><span style="color: #000000"> (
    [</span><span style="color: #0000ff">string</span><span style="color: #000000">]</span><span style="color: #800080">$computerName</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800000">&quot;localhost&quot;</span><span style="color: #000000">
)

</span><span style="color: #008000"># Formatting Options
</span><span style="color: #800080">$OffsetKB</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #000000">@</span><span style="color: #000000">{</span><span style="color: #0000ff">label</span><span style="color: #ff0000">=</span><span style="color: #000000">”</span><span style="color: #0000ff">Offset</span><span style="color: #000000">(</span><span style="color: #0000ff">KB</span><span style="color: #000000">)</span><span style="color: #000000">”</span><span style="color: #0000ff">;Expression</span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0">`</span><span style="color: #000000">
    {</span><span style="color: #000080">$_</span><span style="color: #000000">.</span><span style="color: #0000ff">StartingOffset</span><span style="color: #ff0000">/</span><span style="color: #000000">1024</span><span style="color: #000000"> </span><span style="color: #ff0000">-as</span><span style="color: #000000"> [</span><span style="color: #0000ff">int</span><span style="color: #000000">]}}
</span><span style="color: #800080">$SizeMB</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #000000">@</span><span style="color: #000000">{</span><span style="color: #0000ff">label</span><span style="color: #ff0000">=</span><span style="color: #000000">”</span><span style="color: #0000ff">Size</span><span style="color: #000000">(</span><span style="color: #0000ff">MB</span><span style="color: #000000">)</span><span style="color: #000000">”</span><span style="color: #0000ff">;Expression</span><span style="color: #ff0000">=</span><span style="color: #000000">{</span><span style="color: #000080">$_</span><span style="color: #000000">.</span><span style="color: #0000ff">Size</span><span style="color: #ff0000">/</span><span style="color: #000000">1</span><span style="color: #0000ff">MB</span><span style="color: #000000"> </span><span style="color: #ff0000">-as</span><span style="color: #000000"> [</span><span style="color: #0000ff">int</span><span style="color: #000000">]}} 

</span><span style="color: #008000"># WMI Query
</span><span style="color: #800080">$wmiObj</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0">Get-WmiObject</span><span style="color: #000000"> </span><span style="color: #5f9ea0">-ComputerName</span><span style="color: #000000"> </span><span style="color: #800080">$computerName</span><span style="color: #000000"> </span><span style="color: #5f9ea0">-Class</span><span style="color: #000000"> </span><span style="color: #5f9ea0">`</span><span style="color: #000000">
    </span><span style="color: #800000">&quot;Win32_DiskPartition&quot;</span><span style="color: #000000"> </span><span style="color: #5f9ea0">-ErrorAction</span><span style="color: #000000"> </span><span style="color: #0000ff">SilentlyContinue</span><span style="color: #000000">

</span><span style="color: #008000"># Check for Results
</span><span style="color: #0000ff">if</span><span style="color: #000000">(</span><span style="color: #ff0000">-not</span><span style="color: #000000"> </span><span style="color: #800080">$wmiObj</span><span style="color: #000000">)
{
    </span><span style="color: #008000"># Display Error
</span><span style="color: #000000">    </span><span style="color: #800000">&quot;Can't connect to $computerName&quot;</span><span style="color: #000000">
} </span><span style="color: #0000ff">else</span><span style="color: #000000"> {
    </span><span style="color: #008000"># Display Results
</span><span style="color: #000000">    </span><span style="color: #800080">$wmiObj</span><span style="color: #000000"> </span><span style="color: #0000ff">|</span><span style="color: #000000"> </span><span style="color: #0000ff">ft</span><span style="color: #000000"> </span><span style="color: #0000ff">SystemName</span><span style="color: #000000">,</span><span style="color: #000000"> </span><span style="color: #0000ff">Name</span><span style="color: #000000">,</span><span style="color: #000000"> </span><span style="color: #0000ff">DiskIndex</span><span style="color: #000000">,</span><span style="color: #000000"> </span><span style="color: #800080">$SizeMB</span><span style="color: #000000">,</span><span style="color: #000000"> </span><span style="color: #800080">$OffsetKB</span><span style="color: #000000">  </span><span style="color: #5f9ea0">-AutoSize</span><span style="color: #000000">
}</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.mwjcomputing.com/blog/2010/03/powershell-script-get-diskoffset-ps1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell Script &#8211; Get-ServiceUser.ps1</title>
		<link>http://www.mwjcomputing.com/blog/2010/03/powershell-script-get-serviceuser-ps1/</link>
		<comments>http://www.mwjcomputing.com/blog/2010/03/powershell-script-get-serviceuser-ps1/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 13:03:02 +0000</pubDate>
		<dc:creator>Matt Johnson</dc:creator>
				<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://www.mwjcomputing.com/blog/2010/03/powershell-script-get-serviceuser-ps1/</guid>
		<description><![CDATA[This script gets the services that are running under the specified user. You can download the script here. ###################################################### # Script Name: Get-ServiceUser.ps1 # Written By: Matt Johnson - powershell [at] mwjcomputing.com # Revision Date: 3/17/2010 # Version: 3.0 # Version History: # - 1.0: Initial Script # - 2.0: Enables use of &#124; Out-File [...]]]></description>
			<content:encoded><![CDATA[<p>This script gets the services that are running under the specified user.</p>
<p>You can download the script <a href="http://www.mwjcomputing.com/powershell/get-serviceuser.txt" target="_blank">here</a>.</p>
<pre><span style="color: #008000;">######################################################
# Script Name: Get-ServiceUser.ps1
# Written By: Matt Johnson - powershell [at] mwjcomputing.com
# Revision Date: 3/17/2010
# Version: 3.0
# Version History:
#  - 1.0: Initial Script
#  - 2.0: Enables use of | Out-File
#  - 3.0: Added ability to specify only one machine.
# Description: This script gets a list of services that
#                are running as a particular user from
#                a text file.
# Command Line: ./Get-ServiceUser.ps1
# Example: ./Get-ServiceUser.ps1 -userAccount 'LocalSystem'
#              -filePath "\\fileserver\data\servers.txt"
#          This checks for the user LocalSystem account
#              against names in the servers.txt file.
# Example: ./Get-ServiceUser.ps1 -userAccount 'MWJ\service'
#              -pcName "MAGNET"
#          This checks for the user MWJ\service against
#              the server MAGNET.
# Example: ./Get-ServiceUser.ps1
#          This uses the default options of LocalSystem
#              against c:\fso\data\servers.txt.
######################################################
</span><span style="color: #0000FF;">param</span><span style="color: #000000;"> (
[</span><span style="color: #0000FF;">string</span><span style="color: #000000;">]</span><span style="color: #800080;">$userAccount</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">"LocalSystem"</span><span style="color: #000000;">,</span><span style="color: #000000;">
[</span><span style="color: #0000FF;">string</span><span style="color: #000000;">]</span><span style="color: #800080;">$filePath</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">"c:\fso\data\servers.txt"</span><span style="color: #000000;">,</span><span style="color: #000000;">
[</span><span style="color: #0000FF;">string</span><span style="color: #000000;">]</span><span style="color: #800080;">$pcName</span><span style="color: #000000;">
)

</span><span style="color: #008000;"># Check to see if $pcName is populated.
</span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (</span><span style="color: #FF0000;">-not</span><span style="color: #000000;"> </span><span style="color: #800080;">$pcName</span><span style="color: #000000;">) {
    </span><span style="color: #008000;"># Get content of text file.
</span><span style="color: #000000;">    </span><span style="color: #800080;">$servers</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #5F9EA0;">Get-Content</span><span style="color: #000000;"> </span><span style="color: #5F9EA0;">-path</span><span style="color: #000000;"> </span><span style="color: #800080;">$filePath</span><span style="color: #000000;">
} </span><span style="color: #0000FF;">else</span><span style="color: #000000;">
{
    </span><span style="color: #008000;"># Set list of servers to name of entered PC.
</span><span style="color: #000000;">    </span><span style="color: #800080;">$servers</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$pcName</span><span style="color: #000000;">
}

</span><span style="color: #008000;"># Loop through each line of the text file.
</span><span style="color: #0000FF;">foreach</span><span style="color: #000000;"> (</span><span style="color: #800080;">$server</span><span style="color: #000000;"> </span><span style="color: #0000FF;">in</span><span style="color: #000000;"> </span><span style="color: #800080;">$servers</span><span style="color: #000000;">)
{
    </span><span style="color: #800000;">" "</span><span style="color: #000000;">
    </span><span style="color: #800000;">"Services running as $userAccount on $server"</span><span style="color: #000000;">
    </span><span style="color: #800000;">"-------------------------------------------"</span><span style="color: #000000;">
    </span><span style="color: #008000;"># Get Win32_Service WMI Class
</span><span style="color: #000000;">    </span><span style="color: #800080;">$services</span><span style="color: #000000;"> </span><span style="color: #FF0000;">=</span><span style="color: #000000;"> </span><span style="color: #5F9EA0;">Get-WmiObject</span><span style="color: #000000;"> </span><span style="color: #5F9EA0;">-class</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Win32_Service</span><span style="color: #000000;"> </span><span style="color: #5F9EA0;">`</span><span style="color: #000000;">
    </span><span style="color: #5F9EA0;">-ErrorAction</span><span style="color: #000000;"> </span><span style="color: #0000FF;">SilentlyContinue</span><span style="color: #000000;"> </span><span style="color: #5F9EA0;">-computerName</span><span style="color: #000000;"> </span><span style="color: #800080;">$server</span><span style="color: #000000;">
    </span><span style="color: #008000;"># Check to see if anthing is returned.
</span><span style="color: #000000;">    </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (</span><span style="color: #FF0000;">-not</span><span style="color: #000000;"> </span><span style="color: #800080;">$services</span><span style="color: #000000;">)
    {
        </span><span style="color: #008000;"># Write error message
</span><span style="color: #000000;">        </span><span style="color: #800000;">"Cannot connect to $computer"</span><span style="color: #000000;">
    } </span><span style="color: #0000FF;">else</span><span style="color: #000000;">
    {
        </span><span style="color: #008000;"># Loop through each service and display the name.
</span><span style="color: #000000;">        </span><span style="color: #0000FF;">foreach</span><span style="color: #000000;"> (</span><span style="color: #800080;">$service</span><span style="color: #000000;"> </span><span style="color: #0000FF;">in</span><span style="color: #000000;"> </span><span style="color: #800080;">$services</span><span style="color: #000000;">)
        {
            </span><span style="color: #800080;">$service</span><span style="color: #000000;"> </span><span style="color: #0000FF;">|</span><span style="color: #000000;"> </span><span style="color: #0000FF;">where</span><span style="color: #000000;"> {</span><span style="color: #000080;">$_</span><span style="color: #000000;">.</span><span style="color: #8B4513;">StartName</span><span style="color: #000000;"> </span><span style="color: #FF0000;">-like</span><span style="color: #000000;"> </span><span style="color: #800080;">$userAccount</span><span style="color: #000000;">} </span><span style="color: #5F9EA0;">`</span><span style="color: #000000;">
            </span><span style="color: #0000FF;">|</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Select</span><span style="color: #000000;"> </span><span style="color: #0000FF;">DisplayName</span><span style="color: #000000;">
        }
    }
}</span>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.mwjcomputing.com/blog/2010/03/powershell-script-get-serviceuser-ps1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
