<?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>API Programming &#187; PowerShell</title>
	<atom:link href="http://www.brangle.com/wordpress/category/tutorials/powershell/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.brangle.com/wordpress</link>
	<description>Just another computer weblog</description>
	<lastBuildDate>Tue, 08 Sep 2009 05:41:12 +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>Combine or Join Two Text Files Using PowerShell</title>
		<link>http://www.brangle.com/wordpress/2009/08/combine-join-two-text-files-using-powershell/</link>
		<comments>http://www.brangle.com/wordpress/2009/08/combine-join-two-text-files-using-powershell/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 03:28:37 +0000</pubDate>
		<dc:creator>lopezg</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows PowerShell]]></category>

		<guid isPermaLink="false">http://www.brangle.com/wordpress/?p=422</guid>
		<description><![CDATA[Merging files together, or to a seperate file, is a snap with PowerShell using the <i>Get-Content</i> cmdlet.  If you've never used the Add-Content cmdlet, I would suggest first reading my other article <a href="/wordpress/2009/08/append-text-to-a-file-using-add-content-in-powershell/" target="_top">Append Text to a File Using Add-Content</a>.  The first thing we need to do is identify our two files, in my case I'll be using <i>file1.log</i> and <i>file2.log</i>.  In the first example, I append all the text of <i>file2.log</i> into the end of <i>file1.log</i>.  In the second example, I'll create a completely new file and dump the contents of both the files into the newly created file.  In the last example, I'll add the current date to the filename of a completly new log file.]]></description>
			<content:encoded><![CDATA[<p>Merging files together, or to a seperate file, is a snap with PowerShell using the <i>Get-Content</i> cmdlet.  If you&#8217;ve never used the Add-Content cmdlet, I would suggest first reading my other article <a href="/wordpress/2009/08/append-text-to-a-file-using-add-content-in-powershell/" target="_top">Append Text to a File Using Add-Content</a>.  The first thing we need to do is identify our two files, in my case I&#8217;ll be using <i>file1.log</i> and <i>file2.log</i>.  In the first example, I append all the text of <i>file2.log</i> into the end of <i>file1.log</i>.  In the second example, I&#8217;ll create a completely new file and dump the contents of both the files into the newly created file.  In the last example, I&#8217;ll add the current date to the filename of a completly new log file.<span id="more-422"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$file2</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Content</span> <span style="color: #800000;">&quot;file2.log&quot;</span>
<span style="color: #008080; font-weight: bold;">Add-Content</span> <span style="color: #800000;">&quot;file1.log&quot;</span> $file2</pre></td></tr></table></div>

<p>Now, what if we want to copy the contents of <i>file1.log</i> and <i>file2.log</i> into a completely new file called <i>file3.log</i></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">New-Item</span> <span style="color: #008080; font-style: italic;">-ItemType</span> file <span style="color: #800000;">&quot;file3.log&quot;</span>
<span style="color: #800080;">$file1</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Content</span> <span style="color: #800000;">&quot;file1.log&quot;</span>
<span style="color: #800080;">$file2</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Content</span> <span style="color: #800000;">&quot;file2.log&quot;</span>
<span style="color: #008080; font-weight: bold;">Add-Content</span> <span style="color: #800000;">&quot;file3.log&quot;</span> <span style="color: #800080;">$file1</span>
<span style="color: #008080; font-weight: bold;">Add-Content</span> <span style="color: #800000;">&quot;file3.log&quot;</span> $file2</pre></td></tr></table></div>

<p>What if we want to erase everything in file3.log before we add new content? In this case, instead of creating a new file, we&#8217;ll use the Clear-Contents cmdlet.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">Clear-Content</span> <span style="color: #800000;">&quot;file3.log&quot;</span>
<span style="color: #800080;">$file1</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Content</span> <span style="color: #800000;">&quot;file1.log&quot;</span>
<span style="color: #800080;">$file2</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Content</span> <span style="color: #800000;">&quot;file2.log&quot;</span>
<span style="color: #008080; font-weight: bold;">Add-Content</span> <span style="color: #800000;">&quot;file3.log&quot;</span> <span style="color: #800080;">$file1</span>
<span style="color: #008080; font-weight: bold;">Add-Content</span> <span style="color: #800000;">&quot;file3.log&quot;</span> $file2</pre></td></tr></table></div>

<p>Ok, well, what if I don&#8217;t know if file3.log already exists? If it doesn&#8217;t exist and I run the Clear-Contents cmdlet then I&#8217;ll get an error. And if it does exist and I try to create it as a new file I&#8217;ll still get an error.  There&#8217;s an easy way to do this, we&#8217;ll use the New-Item cmdlet from the example above, but we&#8217;ll add the -force argument, so even if the file exists it will overwrite it.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">New-Item</span> <span style="color: #008080; font-style: italic;">-ItemType</span> file <span style="color: #800000;">&quot;file3.log&quot;</span> <span style="color: #008080; font-style: italic;">-force</span>
<span style="color: #800080;">$file1</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Content</span> <span style="color: #800000;">&quot;file1.log&quot;</span>
<span style="color: #800080;">$file2</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Content</span> <span style="color: #800000;">&quot;file2.log&quot;</span>
<span style="color: #008080; font-weight: bold;">Add-Content</span> <span style="color: #800000;">&quot;file3.log&quot;</span> <span style="color: #800080;">$file1</span>
<span style="color: #008080; font-weight: bold;">Add-Content</span> <span style="color: #800000;">&quot;file3.log&quot;</span> $file2</pre></td></tr></table></div>

<p>Alright, so I guess I got the hang of this, now lastly since these are log files, how can I append the date to the file name? Simple, with the <i>Get-Date</i> cmdlet.  Let&#8217;s output our file name as YYYYMMDD-WebAccess.log in this example.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$date</span><span style="color: pink;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-Date</span><span style="color: #000000;">&#41;</span>.ToString<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;yyyyMMdd&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$NewFileName</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;$date-WebAccess.log&quot;</span>
<span style="color: #008080; font-weight: bold;">New-Item</span> <span style="color: #008080; font-style: italic;">-ItemType</span> file <span style="color: #800080;">$NewFileName</span>
<span style="color: #800080;">$file1</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Content</span> <span style="color: #800000;">&quot;file1.log&quot;</span>
<span style="color: #800080;">$file2</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Content</span> <span style="color: #800000;">&quot;file2.log&quot;</span>
<span style="color: #008080; font-weight: bold;">Add-Content</span> <span style="color: #800080;">$NewFileName</span> <span style="color: #800080;">$file1</span>
<span style="color: #008080; font-weight: bold;">Add-Content</span> <span style="color: #800080;">$NewFileName</span> $file2</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.brangle.com/wordpress/2009/08/combine-join-two-text-files-using-powershell/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Retrieve File Permissions using Get-Acl with PowerShell</title>
		<link>http://www.brangle.com/wordpress/2009/08/retrieve-file-permissions-using-get-acl-with-powershell/</link>
		<comments>http://www.brangle.com/wordpress/2009/08/retrieve-file-permissions-using-get-acl-with-powershell/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 06:30:24 +0000</pubDate>
		<dc:creator>lopezg</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows PowerShell]]></category>

		<guid isPermaLink="false">http://www.brangle.com/wordpress/?p=385</guid>
		<description><![CDATA[Retrieving the owner and permissions of a file, folders and even registry keys is a breeze with PowerShell's Get-Acl cmdlet.  Let's try checking to see who has access to to the <i>C:\Documents and Settings\Administrator</i> folder.]]></description>
			<content:encoded><![CDATA[<p>Retrieving the owner and permissions of a file, folders and even registry keys is a breeze with PowerShell&#8217;s Get-Acl cmdlet.  Let&#8217;s try checking to see who has access to to the <i>C:\Documents and Settings\Administrator</i> folder.<span id="more-385"></span></p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">Get-Acl</span> <span style="color: #800000;">&quot;C:\Documents and Settings\Administrator&quot;</span></pre></div></div>

<p> Now this return everything that I would expect it to, but I prefer the <i>Format-List</i> view, so let&#8217;s check the permissions on the the file <i>C:\Windows\clock.avi</i> and output it in a list view.</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">Get-Acl</span> <span style="color: #800000;">&quot;C:\Windows\clock.avi&quot;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Format-List</span></pre></div></div>

<p>Ok, now I did say we could check the permissions of a registry key, so let&#8217;s go for it&#8230;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">Get-Acl</span> HKLM:\Software\Microsoft</pre></td></tr></table></div>

<p>Now if you just want to find out the owner of the file you could pull back just that value</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">Get-Acl</span> <span style="color: #800000;">&quot;C:\Windows\clock.avi&quot;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> Owner</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.brangle.com/wordpress/2009/08/retrieve-file-permissions-using-get-acl-with-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Ping a Computer using PowerShell</title>
		<link>http://www.brangle.com/wordpress/2009/08/how-to-ping-a-computer-using-powershell/</link>
		<comments>http://www.brangle.com/wordpress/2009/08/how-to-ping-a-computer-using-powershell/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 04:22:19 +0000</pubDate>
		<dc:creator>lopezg</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows PowerShell]]></category>

		<guid isPermaLink="false">http://www.brangle.com/wordpress/?p=380</guid>
		<description><![CDATA[Pinging a computer is really simple, and of course since this is PowerShell we don't want to just use something as primitive as <i>ping.exe</i>, we want to use .NET and take advantage of all the method calls and filters.]]></description>
			<content:encoded><![CDATA[<p>Pinging a computer is really simple, and of course since this is PowerShell we don&#8217;t want to use something as primitive as <i>ping.exe</i>, we want to use .NET and take advantage of all the method calls and filters.<span id="more-380"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$ping</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Net.NetworkInformation.Ping
<span style="color: #800080;">$ping</span>.Send<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;www.brangle.com&quot;</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p>We can also set a timeout so that our computer doesn&#8217;t hang to long on a server that won&#8217;t respond. Let&#8217;s add a timeout of a 5 seconds, we will first need to convert this to milliseconds, so that&#8217;s 5,000ms. Of course 5 seconds may not be a resonable timeout, you need to figure out what&#8217;s appropriate for you and what you&#8217;re willing to tolerate.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$ping</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Net.NetworkInformation.Ping
<span style="color: #800080;">$ping</span>.Send<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;www.brangle.com&quot;</span><span style="color: pink;">,</span> <span style="color: #000000;">5000</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p>Technical details: System.Net.NetworkInformation.Ping requires that you have .NET 2.0 or greater.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brangle.com/wordpress/2009/08/how-to-ping-a-computer-using-powershell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using the System.Environment Class in PowerShell</title>
		<link>http://www.brangle.com/wordpress/2009/08/using-the-system-environment-class-in-powershell/</link>
		<comments>http://www.brangle.com/wordpress/2009/08/using-the-system-environment-class-in-powershell/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 08:24:58 +0000</pubDate>
		<dc:creator>lopezg</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows PowerShell]]></category>

		<guid isPermaLink="false">http://www.brangle.com/wordpress/?p=369</guid>
		<description><![CDATA[The Environment class has a huge array of information and accessing this information is very simple, I'm going to try and give a whole bunch of one line examples of how to do this using PowerShell.]]></description>
			<content:encoded><![CDATA[<p>The Environment class has a huge array of information and accessing this information is very simple, I&#8217;m going to try and give a whole bunch of one line examples of how to do this using PowerShell.<span id="more-369"></span></p>
<p>To retrieve the comptuer name</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>System.Environment<span style="color: #000000;">&#93;</span>::MachineName</pre></td></tr></table></div>

<p>Get Operating System Information (such as Platform, service pack, version, and version string)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>System.Environment<span style="color: #000000;">&#93;</span>::OSVersion</pre></td></tr></table></div>

<p>Checking to see if your computer has started to shutdown</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>System.Environment<span style="color: #000000;">&#93;</span>::HasShutdownStarted</pre></td></tr></table></div>

<p>Instead of trying to remember if you should use <i>`r`n</i> or is it just <i>`n</i>? A simple way is just to get .NET to tell you and assign this value to a variable.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$nl</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>System.Environment<span style="color: #000000;">&#93;</span>::NewLine</pre></td></tr></table></div>

<p>Get the system directory (normally this is C:\Windows\System32), but for some computers it could be different</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>System.Environment<span style="color: #000000;">&#93;</span>::SystemDirectory</pre></td></tr></table></div>

<p>Get the user&#8217;s domain name</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>System.Environment<span style="color: #000000;">&#93;</span>::UserDomainName</pre></td></tr></table></div>

<p>Get the user&#8217;s name</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>System.Environment<span style="color: #000000;">&#93;</span>::UserName</pre></td></tr></table></div>

<p>Get a list of all environment variables</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>System.Environment<span style="color: #000000;">&#93;</span>::GetEnvironmentVariables<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p>Get a particular environment variable</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$path</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>System.Environment<span style="color: #000000;">&#93;</span>::GetEnvironmentVariable<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;path&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$temp</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>System.Environment<span style="color: #000000;">&#93;</span>::GetEnvironmentVariable<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;temp&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$os</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>System.Environment<span style="color: #000000;">&#93;</span>::GetEnvironmentVariable<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;os&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$homedrive</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>System.Environment<span style="color: #000000;">&#93;</span>::GetEnvironmentVariable<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;homedrive&quot;</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p>Create a new environment variable, or overwrite an existing one</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>System.Environment<span style="color: #000000;">&#93;</span>::SetEnvironmentVariable<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;VariableName&quot;</span><span style="color: pink;">,</span><span style="color: #800000;">&quot;VariableValue&quot;</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p>Get all logical drives</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>System.Environment<span style="color: #000000;">&#93;</span>::GetLogicalDrives<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.brangle.com/wordpress/2009/08/using-the-system-environment-class-in-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Send eMail and SMS Text Messages with PowerShell</title>
		<link>http://www.brangle.com/wordpress/2009/08/send-email-messages-with-powershell/</link>
		<comments>http://www.brangle.com/wordpress/2009/08/send-email-messages-with-powershell/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 05:03:04 +0000</pubDate>
		<dc:creator>lopezg</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows Management Instrumentation (WMI)]]></category>
		<category><![CDATA[Windows PowerShell]]></category>

		<guid isPermaLink="false">http://www.brangle.com/wordpress/?p=358</guid>
		<description><![CDATA[Thanks to the .NET library sending emails with PowerShell is surprisingly very simple!  One thing to remember is line breaks, when you need a new line, make sure to use the escape characters <i>`n</i> . In the first example, I'll send just a regular email, in the second I'll send a SMS text message.]]></description>
			<content:encoded><![CDATA[<p>Thanks to the .NET library sending emails with PowerShell is surprisingly very simple!  One thing to remember is line breaks, when you need a new line, make sure to use the escape characters <i>`n</i> . In the first example, I&#8217;ll send just a regular email, in the second I&#8217;ll send a SMS text message.<span id="more-358"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$emailFrom</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;sender@example.com&quot;</span>
<span style="color: #800080;">$emailTo</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;recipient@example.com&quot;</span>
&nbsp;
<span style="color: #800080;">$subject</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Subject&quot;</span>
<span style="color: #800080;">$body</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;This is my automated email<span style="color: #008080; font-weight: bold;">`n</span>This is line number 2&quot;</span>
<span style="color: #800080;">$smtpServer</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;localhost&quot;</span>
&nbsp;
<span style="color: #800080;">$smtp</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">new-object</span> Net.Mail.SmtpClient<span style="color: #000000;">&#40;</span><span style="color: #800080;">$smtpServer</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$smtp</span>.Send<span style="color: #000000;">&#40;</span><span style="color: #800080;">$emailFrom</span><span style="color: pink;">,</span> <span style="color: #800080;">$emailTo</span><span style="color: pink;">,</span> <span style="color: #800080;">$subject</span><span style="color: pink;">,</span> <span style="color: #800080;">$body</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p>Now let&#8217;s send a SMS text massage alert, in this message we will include how much free space we have on our C: drive.  Most cell carriers limit text messages to 160 characters, so we want to keep them as short and useful as possible. Check the list below to see see what the email address of your phone is and make sure to replace the <i>$to</i> variable.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$freeSpace</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">gwmi</span> win32_logicaldisk <span style="color: pink;">-</span><span style="color: #0000FF;">filter</span> <span style="color: #800000;">&quot;DeviceID=<span style="color: #008080; font-weight: bold;">`&quot;</span>C:<span style="color: #008080; font-weight: bold;">`&quot;</span>&quot;</span> <span style="color: pink;">|</span> <span style="color: pink;">%</span> <span style="color: #000000;">&#123;</span> <span style="color: #000080;">$_</span>.freespace<span style="color: pink;">/</span>1GB <span style="color: #000000;">&#125;</span>
<span style="color: #800080;">$freeSpace</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>System.Math<span style="color: #000000;">&#93;</span>::round<span style="color: #000000;">&#40;</span><span style="color: #800080;">$FreeSpace</span><span style="color: pink;">,</span><span style="color: #000000;">2</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #800080;">$from</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;from@example.com&quot;</span>
<span style="color: #800080;">$to</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;1234567890@example.com&quot;</span>
&nbsp;
<span style="color: #800080;">$subject</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;&quot;</span>
<span style="color: #800080;">$body</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;C: free space is &quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$freeSpace</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot; GB&quot;</span>
&nbsp;
<span style="color: #800080;">$smtpServer</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;localhost&quot;</span>
<span style="color: #800080;">$smtp</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> Net.Mail.SmtpClient<span style="color: #000000;">&#40;</span><span style="color: #800080;">$smtpServer</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$smtp</span>.Send<span style="color: #000000;">&#40;</span><span style="color: #800080;">$from</span><span style="color: pink;">,</span> <span style="color: #800080;">$to</span><span style="color: pink;">,</span> <span style="color: #800080;">$subject</span><span style="color: pink;">,</span> <span style="color: #800080;">$body</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p>Now we need to figure out what email address to use so that we can send the SMS address, below are a few examples for several US carriers.  Make sure to replace 1234567890 with your ten digit phone number.</p>
<p>Alltel<br />
1234567890@message.alltel.com</p>
<p>AT&#038;T<br />
1234567890@txt.att.net</p>
<p>Boost Mobile<br />
1234567890@myboostmobile.com</p>
<p>MetroPCS<br />
1234567890@mymetropcs.com</p>
<p>Nextel<br />
1234567890@messaging.nextel.com</p>
<p>Sprint PCS<br />
1234567890@messaging.sprintpcs.com</p>
<p>T-Mobile<br />
1234567890@tmomail.net</p>
<p>Verizon<br />
1234567890@vtext.com</p>
<p>Virgin Mobile<br />
1234567890@vmobl.com</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brangle.com/wordpress/2009/08/send-email-messages-with-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Append Text to a File Using Add-Content in PowerShell</title>
		<link>http://www.brangle.com/wordpress/2009/08/append-text-to-a-file-using-add-content-in-powershell/</link>
		<comments>http://www.brangle.com/wordpress/2009/08/append-text-to-a-file-using-add-content-in-powershell/#comments</comments>
		<pubDate>Sun, 23 Aug 2009 23:28:10 +0000</pubDate>
		<dc:creator>lopezg</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows PowerShell]]></category>

		<guid isPermaLink="false">http://www.brangle.com/wordpress/?p=321</guid>
		<description><![CDATA[Here's a quick tutorial on how to add text to the end of a text file using the <i>Add-Content</i> or its alias <i>ac</i> in PowerShell. In this first example let's add &#34;This is the last line&#34; to the end of a file.]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quick tutorial on how to add text to the end of a text file using the <i>Add-Content</i> or its alias <i>ac</i> in PowerShell. In this first example let&#8217;s add &quot;This is the last line&quot; to the end of a file.<span id="more-321"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">Add-Content</span> c:\sample.txt <span style="color: #800000;">&quot;This is the last line&quot;</span></pre></td></tr></table></div>

<p>  The example above adds the text to the last line, it doesn&#8217;t actually create a new line, so let&#8217;s try it again, and make sure that this time the text that we concatenate is on the last line all by itself.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">Add-Content</span> c:\sample.txt <span style="color: #800000;">&quot;<span style="color: #008080; font-weight: bold;">`r</span><span style="color: #008080; font-weight: bold;">`n</span>This is the last line&quot;</span></pre></td></tr></table></div>

<p>  You&#8217;ll notice a <i>`r`n</i> this is an escape character to tell PowerShell to add a carriage return and a new line, you&#8217;ll need this when working with Windows file.  If your going to move this file to a unix or linux computer, you&#8217;ll only need a <i>`n</i> there&#8217;s no need for the carriage return.</p>
<p>Here is a list of escape characters:</p>
<ul>
<li>`0  &#8212; Null
<li>`a  &#8212; Alert
<li>
<li>`b &#8212; Backspace
<li>`n &#8212; New line
<li>`r &#8212; Carriage return
<li>`t &#8212; Horizontal tab
<li>`&#8217; &#8212; Single quote
<li>`&#8221; &#8212; Double quote</ul>
<p>The example I gave above was the quick and dirty, we should really explicitly state our arguments and use quotes around the path, to do that we will add a path and a value argument</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">Add-Content</span> <span style="color: #008080; font-style: italic;">-Path</span> <span style="color: #800000;">&quot;c:\sample.txt&quot;</span> <span style="color: #008080; font-style: italic;">-Value</span> <span style="color: #800000;">&quot;<span style="color: #008080; font-weight: bold;">`r</span><span style="color: #008080; font-weight: bold;">`n</span>This is the last line&quot;</span></pre></td></tr></table></div>

<p>Here&#8217;s a useful example, suppose you want to map hostname to a particular IP address.  Let&#8217;s map example.com to point to 127.0.0.1, we&#8217;ll do this using the <i>ac</i> alias for <i>Add-Content</i>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">ac</span> <span style="color: #008080; font-style: italic;">-Path</span> <span style="color: #800000;">&quot;C:\WINDOWS\system32\drivers\etc\hosts&quot;</span> <span style="color: #008080; font-style: italic;">-Value</span> <span style="color: #800000;">&quot;<span style="color: #008080; font-weight: bold;">`r</span><span style="color: #008080; font-weight: bold;">`n</span>127.0.0.1    example.com&quot;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.brangle.com/wordpress/2009/08/append-text-to-a-file-using-add-content-in-powershell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Pass Credentials via PowerShell</title>
		<link>http://www.brangle.com/wordpress/2009/08/pass-credentials-via-powershell/</link>
		<comments>http://www.brangle.com/wordpress/2009/08/pass-credentials-via-powershell/#comments</comments>
		<pubDate>Sun, 23 Aug 2009 20:33:07 +0000</pubDate>
		<dc:creator>lopezg</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows Management Instrumentation (WMI)]]></category>
		<category><![CDATA[Windows PowerShell]]></category>

		<guid isPermaLink="false">http://www.brangle.com/wordpress/?p=269</guid>
		<description><![CDATA[I've often found it necessary to pass my Administrator domain or Domain Admin (DomAdmin) credentials to run a PowerShell WMI command.  Fortunately PowerShell provides 3 different ways of doing just that, not counting using Windows built in runas command.  The three methods I'm going to go over are

<ol><li>Entering your own unique credentials</li>
<li>Entering a service account password, ie: the same username (or hard coding a username)
<li>Hard coding a user name and password</li></ol>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve often found it necessary to pass my Administrator domain or Domain Admin (DomAdmin) credentials to run a PowerShell WMI command.  Fortunately PowerShell provides 3 different ways of doing just that, not counting using Windows built in runas command.  The three methods I&#8217;m going to go over are</p>
<ol>
<li>Entering your own unique credentials</li>
<li>Entering a service account password, ie: the same username (or hard coding a username)
<li>Hard coding a user name and password</li>
</ol>
<p><span id="more-269"></span></p>
<p><br /><br /></p>
<p><b>Method 1:</b><div id="attachment_297" class="wp-caption alignleft" style="width: 310px"><a href="http://www.brangle.com/wordpress/wp-content/uploads/2009/08/WindowsPowerShellCredentialsRequest.jpg"><img src="http://www.brangle.com/wordpress/wp-content/uploads/2009/08/WindowsPowerShellCredentialsRequest-300x233.jpg" alt="Windows PowerShell Credentials Request Box" title="Windows PowerShell Credentials Request" width="300" height="233" class="size-medium wp-image-297" /></a><p class="wp-caption-text">Windows PowerShell Credentials Request Box</p></div> Entering your own unique credentials, this will popup the standard windows login, let&#8217;s store our credentials to a variable called <i>$cred</i>, the benefits of doing this if we want to run multiple commands all under this account we can just recall our credentials without having to enter them every single time.  In this example, after I retrieve my stored credentials I&#8217;ll check to see who is logged onto a computer named dev-ghost.  I&#8217;ll be using <i>gwmi</i> cmdlet which is just an alias for the <i>Get-WmiObject</i> cmdlet.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">PS</span> C:\<span style="color: pink;">&gt;</span> <span style="color: #800080;">$cred</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Credential</span>
&nbsp;
cmdlet <span style="color: #008080; font-weight: bold;">Get-Credential</span> at command pipeline position <span style="color: #000000;">1</span>
Supply values <span style="color: #0000FF;">for</span> the following parameters:
Credential
<span style="color: #008080; font-weight: bold;">PS</span> C:\<span style="color: pink;">&gt;</span> <span style="color: #008080; font-weight: bold;">gwmi</span> win32_LoggedOnUser <span style="color: pink;">-</span>computer <span style="color: #800000;">&quot;dev-ghost&quot;</span> <span style="color: #008080; font-style: italic;">-credential</span> $cred</pre></td></tr></table></div>

<p><br /><br /><br />
<b>Method 2</b><br />
In this example, we are going to do the same as above, except we will specify the username, this is perfect for whenever you use service accounts.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">PS</span> C:\<span style="color: pink;">&gt;</span>PS C:\<span style="color: pink;">&gt;</span> <span style="color: #800080;">$cred</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Credential</span> <span style="color: #800000;">&quot;dev-ghost\administrator&quot;</span>
<span style="color: #008080; font-weight: bold;">PS</span> C:\<span style="color: pink;">&gt;</span> <span style="color: #008080; font-weight: bold;">gwmi</span> win32_LoggedOnUser <span style="color: pink;">-</span>computer <span style="color: #800000;">&quot;dev-ghost&quot;</span> <span style="color: #008080; font-style: italic;">-credential</span> $cred</pre></td></tr></table></div>

<p>Now let&#8217;s do the same as above, but instead of saving our credentials to a variable, we will just use it once and call it inline.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">PS</span> C:\<span style="color: pink;">&gt;</span> <span style="color: #008080; font-weight: bold;">gwmi</span> win32_LoggedOnUser <span style="color: pink;">-</span>computer <span style="color: #800000;">&quot;dev-ghost&quot;</span> <span style="color: #008080; font-style: italic;">-credential</span> <span style="color: #800000;">&quot;dev-ghost\administrator&quot;</span></pre></td></tr></table></div>

<p><br /><br /><br />
<b>Method 3</b><br />
I don&#8217;t think password should ever be hard coded into scripts, especially ones that can be decrypted.  PowerShell provides a SecureString, this is nothing more than a joke. The reason I call it a joke is because anyone can decrypt a SecureString if they know a little bit of PS.  But ignorance is bliss right? So let&#8217;s get to it&#8230;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">PS</span> C:\windows\system32\windowspowershell\v1.0<span style="color: pink;">&gt;</span> <span style="color: #008080; font-weight: bold;">Read-Host</span> <span style="color: #008080; font-style: italic;">-AsSecureString</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">ConvertFrom-SecureString</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out-File</span> C:\PowerShell\MyPassword.txt</pre></td></tr></table></div>

<p>Once you press enter just type in your password, this will save your password to a file called MyPassword.txt. So now that the password is saved as a &quot;SecureString&quot; we can now use these saved credentials.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$password</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">type</span> C:\PowerShell\MyPassword.txt <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">ConvertTo-SecureString</span>
<span style="color: #800080;">$cred</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> <span style="color: #008080; font-style: italic;">-TypeName</span> System.Management.Automation.PSCredential <span style="color: #008080; font-style: italic;">-argumentlist</span> “administrator”<span style="color: pink;">,</span>$password</pre></td></tr></table></div>

<p> and that&#8217;s it, your all set to start impersonating your credentials so that you can run scripts or executable under your service accounts.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brangle.com/wordpress/2009/08/pass-credentials-via-powershell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mounting a Virtual/Network Drive with PowerShell</title>
		<link>http://www.brangle.com/wordpress/2009/08/mounting-a-virtual-network-drive-with-powershell/</link>
		<comments>http://www.brangle.com/wordpress/2009/08/mounting-a-virtual-network-drive-with-powershell/#comments</comments>
		<pubDate>Fri, 14 Aug 2009 06:18:45 +0000</pubDate>
		<dc:creator>lopezg</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows PowerShell]]></category>

		<guid isPermaLink="false">http://www.brangle.com/wordpress/?p=251</guid>
		<description><![CDATA[There's multiple reasons why someone would want to mount a virtual or network drive, especially in an enterprise environment where many users don't understand the concept of UNC paths or when older software doesn't support long path names or UNC connections.  Now there's two things we need to know, is this a local path, or is it somewhere on the network.  Once we know that we can get started.]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s multiple reasons why someone would want to mount a virtual or network drive, especially in an enterprise environment where many users don&#8217;t understand the concept of UNC paths or when older software doesn&#8217;t support long path names or UNC connections.  Now there&#8217;s two things we need to know, is this a local path, or is it somewhere on the network.  Once we know that we can get started.<span id="more-251"></span></p>
<p>If the folder you want to mount happens to exist on the same computer, i.e. locally we can use the subst.exe command.  Let&#8217;s assume we want to mount the administrators photos to the drive letter P: we should run the following in the command prompt:</p>
<pre>subst P: "C:\Documents and Settings\Administrator\My Documents\My Pictures"</pre>
<p>Do not put a trailing slash at the end of Pictures, subst.exe doesn&#8217;t like it and will complain that it can&#8217;t find the path. Of course you don&#8217;t even need to run this command from the command prompt, you could run it from the Run menu.  In general the command to create a virtual drive is</p>
<pre>subst [drive1:] [drive2:]path]</pre>
<p> where drive1 is the drive letter that you want to create and drive2:path is the file location of the folder you want to map.</p>
<p>Ok, so now we&#8217;v created the virtual drive and we&#8217;re ready to get rid of it. This procedure isn&#8217;t as easy as right clicking on the drive and selecting Disconnect, after all you can&#8217;t disconnect if it&#8217;s a local folder. You&#8217;re going to have to delete the virtual drive using the delete switch /d</p>
<pre>subst P: /d</pre>
<p> It really can&#8217;t get any simplier.</p>
<p>Ok, so now let&#8217;s try mapping a UNC drive with PowerShell. It&#8217;s just that simple.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$drive</span> <span style="color: pink;">=</span> $<span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">New-Object</span> <span style="color: pink;">-</span>Com WScript.Network<span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$drive</span>.MapNetworkDrive<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;w:&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;\\ComputerName\Share&quot;</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.brangle.com/wordpress/2009/08/mounting-a-virtual-network-drive-with-powershell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>List of Available PowerShell Cmdlets</title>
		<link>http://www.brangle.com/wordpress/2009/08/list-of-available-powershell-cmdlets/</link>
		<comments>http://www.brangle.com/wordpress/2009/08/list-of-available-powershell-cmdlets/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 08:33:18 +0000</pubDate>
		<dc:creator>lopezg</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Windows PowerShell]]></category>

		<guid isPermaLink="false">http://www.brangle.com/wordpress/?p=12</guid>
		<description><![CDATA[PowerShell is a completly new scripting language to me and as such there's so much I don't know about it, and while I can browse the net all day looking for information, I wanted to see how I could get PowerShell to tell me everything it knows first before I turn to the almighty Google. Searching for available Microsoft PowerShell Cmdlet descriptions (pronounced command-lets) and what they do I used the get-help command. After I ran this, I immediately noticed a Get-Help * command appear, so off I went.]]></description>
			<content:encoded><![CDATA[<p>PowerShell is a completly new scripting language to me and as such there&#8217;s so much I don&#8217;t know about it, and while I can browse the net all day looking for information, I wanted to see how I could get PowerShell to tell me everything it knows first before I turn to the almighty Google. Searching for available Microsoft PowerShell Cmdlet descriptions (pronounced command-lets) and what they do I used the <span>get-help</span> command. After I ran this, I immediately noticed a Get-Help * command appear, so off I went.<span id="more-12"></span></p>
<pre><span>Get-Help *</span></pre>
<p>Well honestly this returned more than I was expecting in included aliases, providers, and help files, I on the otherhand was only interested in cmdlets, at least for the moment. So in true PowerShell style, I ran the following query against PowerShell to only show me the cmdlets in the help section.</p>
<pre><span>Get-Help * | Where-Object { $_.Category -eq 'Cmdlet' }</span></pre>
<p>Of course, this also told me that that the category was a Cmdlet and to keep things looking nice, I decided to filter out only what I wanted by taking it a step further and running another query against my query&#8230;</p>
<pre><span>Get-Help * | Where-Object { $_.Category -eq 'Cmdlet' } | Select Name,Synopsis,PSSnapIn | Sort Name</span></pre>
<p>The following command returned a lot of useful information about PowerShell cmdlets.  Every item in the PSSnapIn should be prefixed with &#8220;Microsoft.PowerShell,&#8221; I just edited it out room to make it look cleaner.</p>
<table border="1">
<tbody>
<tr>
<td>Name</td>
<td>Synopsis</td>
<td>PSSnapIn</td>
</tr>
<tr>
<td><a href="/wordpress/2009/08/append-text-to-a-file-using-add-content-in-powershell/">Add-Content</a></td>
<td>Adds content to the specified item(s).</td>
<td>Management</td>
</tr>
<tr>
<td>Add-History</td>
<td>Appends entries to the session history.</td>
<td>Core</td>
</tr>
<tr>
<td>Add-Member</td>
<td>Adds a user-defined custom member to an instance of a Windows PowerShell object.</td>
<td>Utility</td>
</tr>
<tr>
<td>Add-PSSnapin</td>
<td>Adds one or more Windows PowerShell snap-ins to the current console.</td>
<td>Core</td>
</tr>
<tr>
<td>Clear-Content</td>
<td>Deletes the contents of a item, such as deleting the text from a file, but does not delete the item.</td>
<td>Management</td>
</tr>
<tr>
<td>Clear-Item</td>
<td>Deletes the contents of an item, but does not delete the item.</td>
<td>Management</td>
</tr>
<tr>
<td>Clear-ItemProperty</td>
<td>Deletes the value of a property but it does not delete the property.</td>
<td>Management</td>
</tr>
<tr>
<td>Clear-Variable</td>
<td>Deletes the value of a variable.</td>
<td>Utility</td>
</tr>
<tr>
<td>Compare-Object</td>
<td>Compares two sets of objects.</td>
<td>Utility</td>
</tr>
<tr>
<td>ConvertFrom-SecureString</td>
<td>Converts a secure string into an encrypted standard string.</td>
<td>Security</td>
</tr>
<tr>
<td>Convert-Path</td>
<td>Converts a path from a Windows PowerShell path to a Windows PowerShell provider path.</td>
<td>Management</td>
</tr>
<tr>
<td>ConvertTo-Html</td>
<td>Creates an HTML page that represents an object or a set of objects.</td>
<td>Utility</td>
</tr>
<tr>
<td>ConvertTo-SecureString</td>
<td>Converts encrypted standard strings to secure strings. It can also convert plain text to secure strings. It is used with ConvertFrom-SecureString and Read-Host.</td>
<td>.Security</td>
</tr>
<tr>
<td>Copy-Item</td>
<td>Copies an item from one location to another within a namespace.</td>
<td>Management</td>
</tr>
<tr>
<td>Copy-ItemProperty</td>
<td>Copies a property and value from a specified location to another location.</td>
<td>Management</td>
</tr>
<tr>
<td>Export-Alias</td>
<td>Exports information about currently-defined aliases to a file.</td>
<td>Utility</td>
</tr>
<tr>
<td>Export-Clixml</td>
<td>Creates an XML-based representation of an object or objects and stores it in a file.</td>
<td>Utility</td>
</tr>
<tr>
<td>Export-Console</td>
<td>Exports the configuration of the current console to a file so that you can reuse or share it.</td>
<td>Core</td>
</tr>
<tr>
<td>Export-Csv</td>
<td>Creates a comma-separated values (CSV) file that represents the input objects.</td>
<td>Utility</td>
</tr>
<tr>
<td>ForEach-Object</td>
<td>Performs an operation against each of a set of input objects.</td>
<td>Core</td>
</tr>
<tr>
<td>Format-Custom</td>
<td>Uses a customized view to format the output.</td>
<td>Utility</td>
</tr>
<tr>
<td>Format-List</td>
<td>Formats the output as a list of properties in which each property appears on a new line.</td>
<td>Utility</td>
</tr>
<tr>
<td>Format-Table</td>
<td>Formats the output as a table.</td>
<td>Utility</td>
</tr>
<tr>
<td>Format-Wide</td>
<td>Formats objects as a wide table that displays only one property of each object.</td>
<td>Utility</td>
</tr>
<tr>
<td><a href="/wordpress/2009/08/retrieve-file-permissions-using-get-acl-with-powershell/" target="_top">Get-Acl</a></td>
<td>Gets the security descriptor for a resource, such as a file or registry key.</td>
<td>Security</td>
</tr>
<tr>
<td>Get-Alias</td>
<td>Gets the aliases for the current session.</td>
<td>Utility</td>
</tr>
<tr>
<td>Get-AuthenticodeSignature</td>
<td>Gets information about the Authenticode signature in a file.</td>
<td>Security</td>
</tr>
<tr>
<td>Get-ChildItem</td>
<td>Gets the items and child items in one or more specified locations.</td>
<td>Management</td>
</tr>
<tr>
<td>Get-Command</td>
<td>Gets basic information about cmdlets and about other elements of Windows PowerShell commands.</td>
<td>Core</td>
</tr>
<tr>
<td>Get-Content</td>
<td>Gets the content of the item at the specified location.</td>
<td>Management</td>
</tr>
<tr>
<td><a href="/wordpress/2009/08/pass-credentials-via-powershell/">Get-Credential</a></td>
<td>Gets a credential object based on a user name and password.</td>
<td>Security</td>
</tr>
<tr>
<td>Get-Culture</td>
<td>Gets information about the regional settings on a computer.</td>
<td>Utility</td>
</tr>
<tr>
<td>Get-Date</td>
<td>Gets the current date and time.</td>
<td>Utility</td>
</tr>
<tr>
<td>Get-EventLog</td>
<td>Gets information about local event logs or the entries stored in those event logs.</td>
<td>Management</td>
</tr>
<tr>
<td>Get-ExecutionPolicy</td>
<td>Gets the current execution policy for the shell.</td>
<td>Security</td>
</tr>
<tr>
<td>Get-Help</td>
<td>Displays information about Windows PowerShell cmdlets and concepts.</td>
<td>Core</td>
</tr>
<tr>
<td>Get-History</td>
<td>Gets a list of the commands entered during the current session.</td>
<td>Core</td>
</tr>
<tr>
<td>Get-Host</td>
<td>Gets a reference to the current console host object. Displays Windows Powershell version and regional information by default.</td>
<td>Utility</td>
</tr>
<tr>
<td>Get-Item</td>
<td>Gets the item at the specified location.</td>
<td>Management</td>
</tr>
<tr>
<td>Get-ItemProperty</td>
<td>Retrieves the properties of a specified item.</td>
<td>Management</td>
</tr>
<tr>
<td>Get-Location</td>
<td>Gets information about the current working location.</td>
<td>Management</td>
</tr>
<tr>
<td>Get-Member</td>
<td>Gets information about objects or collections of objects.</td>
<td>Utility</td>
</tr>
<tr>
<td>Get-PfxCertificate</td>
<td>Gets information about .pfx certificate files on the computer.</td>
<td>Security</td>
</tr>
<tr>
<td>Get-Process</td>
<td>Gets the processes that are running on the local computer.</td>
<td>Management</td>
</tr>
<tr>
<td>Get-PSDrive</td>
<td>Gets information about Windows PowerShell drives.</td>
<td>Management</td>
</tr>
<tr>
<td>Get-PSProvider</td>
<td>Gets information about the specified Windows PowerShell provider.</td>
<td>Management</td>
</tr>
<tr>
<td>Get-PSSnapin</td>
<td>Gets the Windows PowerShell snap-ins on the computer.</td>
<td>Core</td>
</tr>
<tr>
<td>Get-Service</td>
<td>Gets the services on the local computer.</td>
<td>Management</td>
</tr>
<tr>
<td>Get-TraceSource</td>
<td>Gets the Windows PowerShell components that are instrumented for tracing.</td>
<td>Utility</td>
</tr>
<tr>
<td>Get-UICulture</td>
<td>gets information about the current user interface culture for Windows PowerShell.</td>
<td>Utility</td>
</tr>
<tr>
<td>Get-Unique</td>
<td>Returns the unique items from a sorted list.</td>
<td>Utility</td>
</tr>
<tr>
<td>Get-Variable</td>
<td>Gets the variables in the current console.</td>
<td>Utility</td>
</tr>
<tr>
<td>Get-WmiObject</td>
<td>Gets instances of WMI classes or information about available classes.</td>
<td>Management</td>
</tr>
<tr>
<td>Group-Object</td>
<td>Groups objects that contain the same value for specified properties.</td>
<td>Utility</td>
</tr>
<tr>
<td>Import-Alias</td>
<td>Imports an alias list from a file.</td>
<td>Utility</td>
</tr>
<tr>
<td>Import-Clixml</td>
<td>Imports a CLIXML file and creates corresponding objects within Windows PowerShell.</td>
<td>Utility</td>
</tr>
<tr>
<td>Import-Csv</td>
<td>Imports comma-separated value (CSV) files in the format produced by the Export-CSV cmdlet and returns objects that correspond to the objects represented in that CSV file.</td>
<td>Utility</td>
</tr>
<tr>
<td>Invoke-Expression</td>
<td>Runs a Windows PowerShell expression that is provided in the form of a string.</td>
<td>Utility</td>
</tr>
<tr>
<td>Invoke-History</td>
<td>Runs commands from the session history.</td>
<td>Core</td>
</tr>
<tr>
<td>Invoke-Item</td>
<td>Invokes the provider-specific default action on the specified item.</td>
<td>Management</td>
</tr>
<tr>
<td>Join-Path</td>
<td>Combines a path and child-path into a single path. The provider supplies the path delimiters.</td>
<td>Management</td>
</tr>
<tr>
<td>Measure-Command</td>
<td>Measures the time it takes to run script blocks and cmdlets.</td>
<td>Utility</td>
</tr>
<tr>
<td>Measure-Object</td>
<td>Measures characteristics of objects and their properties.</td>
<td>Utility</td>
</tr>
<tr>
<td>Move-Item</td>
<td>Moves an item from one location to another.</td>
<td>Management</td>
</tr>
<tr>
<td>Move-ItemProperty</td>
<td>Moves a property from one location to another.</td>
<td>Management</td>
</tr>
<tr>
<td>New-Alias</td>
<td>Creates a new alias.</td>
<td>Utility</td>
</tr>
<tr>
<td>New-Item</td>
<td>Creates a new item in a namespace.</td>
<td>Management</td>
</tr>
<tr>
<td>New-ItemProperty</td>
<td>Sets a new property of an item at a location.</td>
<td>Management</td>
</tr>
<tr>
<td>New-Object</td>
<td>Creates an instance of a .Net or COM object.</td>
<td>Utility</td>
</tr>
<tr>
<td>New-PSDrive</td>
<td>Installs a new WIndows PowerShell drive.</td>
<td>Management</td>
</tr>
<tr>
<td>New-Service</td>
<td>Creates a new entry for a Windows Service in the registry and the Service Database.</td>
<td>Management</td>
</tr>
<tr>
<td>New-TimeSpan</td>
<td>Creates a TimeSpan object.</td>
<td>Utility</td>
</tr>
<tr>
<td>New-Variable</td>
<td>Creates a new variable.</td>
<td>Utility</td>
</tr>
<tr>
<td>Out-Default</td>
<td>Send the output to the default formatter and the default output cmdlet. This cmdlet has no effect on the formatting or output. It is a placeholder that lets you write your own Out-Default function or cmdlet.</td>
<td>Utility</td>
</tr>
<tr>
<td>Out-File</td>
<td>Sends output to a file.</td>
<td>Utility</td>
</tr>
<tr>
<td>Out-Host</td>
<td>Sends output to the command line.</td>
<td>Utility</td>
</tr>
<tr>
<td>Out-Null</td>
<td>Deletes output instead of sending it to the console.</td>
<td>Utility</td>
</tr>
<tr>
<td>Out-Printer</td>
<td>Sends output to a printer.</td>
<td>Utility</td>
</tr>
<tr>
<td>Out-String</td>
<td>Sends objects to the host as a series of strings.</td>
<td>Utility</td>
</tr>
<tr>
<td>Pop-Location</td>
<td>Changes the current location to the location most recently pushed onto the stack. You can pop the location from the default stack or from a stack that you create by using Push-Location.</td>
<td>Management</td>
</tr>
<tr>
<td>Push-Location</td>
<td>Pushes the current location onto the stack.</td>
<td>Management</td>
</tr>
<tr>
<td>Read-Host</td>
<td>Reads a line of input from the console.</td>
<td>Utility</td>
</tr>
<tr>
<td>Remove-Item</td>
<td>Deletes the specified items.</td>
<td>Management</td>
</tr>
<tr>
<td>Remove-ItemProperty</td>
<td>Deletes the property and its value from an item.</td>
<td>Management</td>
</tr>
<tr>
<td>Remove-PSDrive</td>
<td>Removes a Windows PowerShell drive from its location.</td>
<td>Management</td>
</tr>
<tr>
<td>Remove-PSSnapin</td>
<td>Removes Windows PowerShell snap-ins from the current console.</td>
<td>Core</td>
</tr>
<tr>
<td>Remove-Variable</td>
<td>Deletes a variable and its value.</td>
<td>Utility</td>
</tr>
<tr>
<td>Rename-Item</td>
<td>Renames an item in a Windows PowerShell provider namespace.</td>
<td>Management</td>
</tr>
<tr>
<td>Rename-ItemProperty</td>
<td>Renames a property of an item.</td>
<td>Management</td>
</tr>
<tr>
<td>Resolve-Path</td>
<td>Resolves the wildcard characters in a path and displays the path contents.</td>
<td>Management</td>
</tr>
<tr>
<td>Restart-Service</td>
<td>Stops and then starts one or more services.</td>
<td>Management</td>
</tr>
<tr>
<td>Resume-Service</td>
<td>Resumes one or more suspended (paused) services.</td>
<td>Management</td>
</tr>
<tr>
<td>Select-Object</td>
<td>Selects specified properties of an object or set of objects. It can also select unique objects from an array of objects or it can select a specified number of objects from the beginning or end of an array of objects.</td>
<td>Utility</td>
</tr>
<tr>
<td>Select-String</td>
<td>Identifies patterns in strings.</td>
<td>Utility</td>
</tr>
<tr>
<td>Set-Acl</td>
<td>Changes the security descriptor of a specified resource, such as a file or a registry key.</td>
<td>Security</td>
</tr>
<tr>
<td>Set-Alias</td>
<td>Creates or changes an alias (alternate name) for a cmdlet or other command element in the current Windows PowerShell session.</td>
<td>Utility</td>
</tr>
<tr>
<td>Set-AuthenticodeSignature</td>
<td>Uses an authenticode signature to sign a Windows PowerShell script or other file.</td>
<td>Security</td>
</tr>
<tr>
<td>Set-Content</td>
<td>Writes or replaces the content in an item with new content.</td>
<td>Management</td>
</tr>
<tr>
<td>Set-Date</td>
<td>Changes the system time on the computer to a time that you specify.</td>
<td>Utility</td>
</tr>
<tr>
<td>Set-ExecutionPolicy</td>
<td>Changes the user preference for the execution policy of the shell.</td>
<td>Security</td>
</tr>
<tr>
<td>Set-Item</td>
<td>Changes the value of an item to the value specified in the command.</td>
<td>Management</td>
</tr>
<tr>
<td>Set-ItemProperty</td>
<td>Sets the value of a property at the specified location.</td>
<td>Management</td>
</tr>
<tr>
<td>Set-Location</td>
<td>Sets the current working location to a specified location.</td>
<td>Management</td>
</tr>
<tr>
<td>Set-PSDebug</td>
<td>Turns script debugging features on and off, sets the trace level and toggles strict mode.</td>
<td>Core</td>
</tr>
<tr>
<td>Set-Service</td>
<td>Changes the display name, description, or starting mode of a service.</td>
<td>Management</td>
</tr>
<tr>
<td>Set-TraceSource</td>
<td>Configures, starts, and stops a trace of Windows PowerShell components.</td>
<td>Utility</td>
</tr>
<tr>
<td>Set-Variable</td>
<td>Sets the value of a variable. Creates the variable if one with the requested name does not exist.</td>
<td>Utility</td>
</tr>
<tr>
<td>Sort-Object</td>
<td>Sorts objects by property values.</td>
<td>Utility</td>
</tr>
<tr>
<td>Split-Path</td>
<td>Returns the specified part of a path.</td>
<td>Management</td>
</tr>
<tr>
<td>Start-Service</td>
<td>Starts one or more stopped services.</td>
<td>Management</td>
</tr>
<tr>
<td>Start-Sleep</td>
<td>Suspend shell, script, or runspace activity for the specified period of time.</td>
<td>Utility</td>
</tr>
<tr>
<td>Start-Transcript</td>
<td>Creates a record of all or part of a Windows PowerShell session in a text file.</td>
<td>Host</td>
</tr>
<tr>
<td>Stop-Process</td>
<td>Stops one or more running processes.</td>
<td>Management</td>
</tr>
<tr>
<td>Stop-Service</td>
<td>Stops one or more running services.</td>
<td>Management</td>
</tr>
<tr>
<td>Stop-Transcript</td>
<td>Stops a transcript.</td>
<td>Host</td>
</tr>
<tr>
<td>Suspend-Service</td>
<td>Suspends (pauses) one or more running services.</td>
<td>Management</td>
</tr>
<tr>
<td>Tee-Object</td>
<td>Pipes object input to a file or variable, then passes the input along the pipeline.</td>
<td>Utility</td>
</tr>
<tr>
<td>Test-Path</td>
<td>Determines whether all elements of a path exist.</td>
<td>Management</td>
</tr>
<tr>
<td>Trace-Command</td>
<td>The Trace-Command cmdlet configures and starts a trace of the specified expression or command.</td>
<td>Utility</td>
</tr>
<tr>
<td>Update-FormatData</td>
<td>Updates and appends format data files.</td>
<td>Utility</td>
</tr>
<tr>
<td>Update-TypeData</td>
<td>Updates the current extended type configuration by reloading the *.types.ps1xml files into memory.</td>
<td>Utility</td>
</tr>
<tr>
<td>Where-Object</td>
<td>Creates a filter that controls which objects will be passed along a command pipeline.</td>
<td>Core</td>
</tr>
<tr>
<td>Write-Debug</td>
<td>Writes a debug message to the host display.</td>
<td>Utility</td>
</tr>
<tr>
<td>Write-Error</td>
<td>Writes an object to the error pipeline.</td>
<td>Utility</td>
</tr>
<tr>
<td>Write-Host</td>
<td>Displays objects by using the host user interface</td>
<td>Utility</td>
</tr>
<tr>
<td>Write-Output</td>
<td>Writes objects to the success pipeline.</td>
<td>Utility</td>
</tr>
<tr>
<td>Write-Progress</td>
<td>Displays a progress bar within a Windows PowerShell command window.</td>
<td>Utility</td>
</tr>
<tr>
<td>Write-Verbose</td>
<td>Writes a string to the verbose display of the host.</td>
<td>Utility</td>
</tr>
<tr>
<td>Write-Warning</td>
<td>Writes a warning message.</td>
<td>Utility</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.brangle.com/wordpress/2009/08/list-of-available-powershell-cmdlets/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Accessing WMI Information From PowerShell</title>
		<link>http://www.brangle.com/wordpress/2009/07/accessing-wmi-information-from-powershell/</link>
		<comments>http://www.brangle.com/wordpress/2009/07/accessing-wmi-information-from-powershell/#comments</comments>
		<pubDate>Sun, 26 Jul 2009 06:51:09 +0000</pubDate>
		<dc:creator>lopezg</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Windows Management Instrumentation (WMI)]]></category>
		<category><![CDATA[Windows PowerShell]]></category>

		<guid isPermaLink="false">http://www.brangle.com/wordpress/?p=8</guid>
		<description><![CDATA[I'm starting to learn how powerful the Windows Management Instrumentation aka Windows WMI is. One of the simpliest ways I found of accessing the information is via Windows PowerShell. Here is a simple PowerShell command that will return the Win32_OperatingSystem information...]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m starting to learn how powerful the Windows Management Instrumentation aka Windows WMI is. One of the simpliest ways I found of accessing the information is via Windows PowerShell. Here is a simple PowerShell command that will return the Win32_OperatingSystem information.<span id="more-8"></span></p>
<pre><span>Get-WmiObject Win32_OperatingSystem</span></pre>
<p>The following command returned the following on my Windows XP box, and yes, anywhere you see XXXXX I censored the data for my personal privacy&#8230;<br />
<span><br />
</span></p>
<pre><span>SystemDirectory : C:\WINDOWS\system32
Organization    : XXXXX
BuildNumber     : 2600
RegisteredUser  : XXXXX
SerialNumber    : XXXXX-XXX-XXXXXXX-XXXXX
Version         : 5.1.2600</span></pre>
<p>If we use a pipe command, we can return the information in a table<br />
<span><br />
</span></p>
<pre><span>PS H:\powershell&gt; Get-WmiObject Win32_OperatingSystem | format-table

SystemDirecto Organization  BuildNumber  RegisteredUs SerialNumber Version
ry                                       er
------------- ------------  -----------  ------------ ------------ -------
C:\WINDOWS... XXXXX...      2600         XXXXX...     XXXXX-XXX... 5.1.2600</span></pre>
<p>Of course, what if we just wanted to return the Windows Version and not all of the miscellaneous/irrelevant data? We can pipe the Get-Member command to see all of the properties that are hidden in that class.</p>
<pre><span>Get-WmiObject Win32_OperatingSystem | Get-Member</span></pre>
<p>Running this command shows us a list of MemberType, if you see a MemberType of Property we can query to see what is contained within that property field by using the Format Table command &#8220;ft.&#8221; For example</p>
<pre><span>PS H:\powershell&gt; Get-WmiObject Win32_OperatingSystem | ft Version, ServicePackMajorVersion

Version                                                 ServicePackMajorVersion
-------                                                 -----------------------
5.1.2600                                                                      3</span></pre>
<p>Now, what if we want to access information on a remote client or server? Simple! just concat the computer name to the WMI call. Just make sure to change &#8220;ComputerName&#8221; to the client/server name.</p>
<pre><span>PS H:\powershell&gt; Get-WmiObject Win32_OperatingSystem -computer "ComputerName" | ft Version, ServicePackMajorVersion</span></pre>
<p>That&#8217;s great, but if you don&#8217;t have access to client/server under your normal Windows or AD credentials, we can authenticate as a different user. To do this we are going to assign our credentials to the variable $cred (short for credentials), you can change this name to whatever you want. Once we&#8217;ve logged in, we will pass those to the client or server that we are trying to authenticate against to login and view the WMI system info. When we call Get-Credential this causes a Windows popup asking us to login.</p>
<pre><span>PS H:\powershell&gt; $cred = Get-Credential

cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
Credential

PS H:\powershell&gt; Get-WmiObject Win32_OperatingSystem -computer dev-ghost -Credential $cred

SystemDirectory : C:\WINDOWS\system32
Organization    : XXXXX
BuildNumber     : 3790
RegisteredUser  : XXXXX
SerialNumber    : XXXXX-XXX-XXXXXXX-XXXXX
Version         : 5.2.3790</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.brangle.com/wordpress/2009/07/accessing-wmi-information-from-powershell/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
