<?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>Nazeeh's Little Corner on the Web &#187; Powershell</title>
	<atom:link href="http://www.nazspace.com/wp/category/powershell/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nazspace.com/wp</link>
	<description>Game Development Demystified!</description>
	<lastBuildDate>Fri, 04 Sep 2009 04:02:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PowerShell Tricks &#8211; Trick 3: Better Prompt!</title>
		<link>http://www.nazspace.com/wp/2007/07/16/powershell-tricks-trick-3-better-prompt/</link>
		<comments>http://www.nazspace.com/wp/2007/07/16/powershell-tricks-trick-3-better-prompt/#comments</comments>
		<pubDate>Mon, 16 Jul 2007 18:07:40 +0000</pubDate>
		<dc:creator>nazeeh</dc:creator>
				<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://www.nazspace.com/wp/2007/07/16/powershell-tricks-trick-3-better-prompt/</guid>
		<description><![CDATA[
This one is a small one really, but I found it to be quite useful. One of the things that irritated me was when I would navigate to a folder that is deeply nested under other folders. The prompt would get so damn long that it&#8217;s eating up the majority of my command line. So [...]]]></description>
			<content:encoded><![CDATA[</p>
<p>This one is a small one really, but I found it to be quite useful. One of the things that irritated me was when I would navigate to a folder that is deeply nested under other folders. The prompt would get so damn long that it&#8217;s eating up the majority of my command line. So I wrote this small prompt function that handles long folders nicely:</p>
<div class="csharpcode">
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
</p></div>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">function</span> prompt </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">{     </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    $pwd = (get-location).path;</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    <span style="color: #0000ff">if</span> ($pwd.Length <span style="color: #cc6633">-gt</span> 40)</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">        $pwd = <span style="color: #006080">"..."</span> + $pwd.substring($pwd.Length - 20, 20);</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    }</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">        </pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    <span style="color: #0000ff">if</span> ($IsAdmin)</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        Write-Host (<span style="color: #006080">"PS (Admin) "</span> + $pwd +<span style="color: #006080">"&gt;"</span>) -nonewline -foregroundcolor Green</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">        $host.ui.rawui.WindowTitle = <span style="color: #006080">"Admin Shell: "</span> + $(get-location)</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    }</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    <span style="color: #0000ff">else</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    {</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">        Write-Host (<span style="color: #006080">"PS "</span> + $pwd +<span style="color: #006080">"&gt;"</span>) -nonewline -foregroundcolor Green</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        $host.ui.rawui.WindowTitle = <span style="color: #006080">"Windows Powershell: "</span> + $(get-location)</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    }</pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    <span style="color: #0000ff">return</span> <span style="color: #006080">" "</span></pre>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">}</pre>
</div>
</div>
<p>What this does is it checks if the current path is longer than 40 characters, if it is, it truncates it to the last 20 characters preceded by &#8220;&#8230;&#8221;.&nbsp;&nbsp;</p>
<p>So as you can see, the path is nice and short and will never be larger than this size. The window title displays the full path so that you can tell with a glance exactly where you are. </p>
<p>Have fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nazspace.com/wp/2007/07/16/powershell-tricks-trick-3-better-prompt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell Tricks &#8211; Trick 2</title>
		<link>http://www.nazspace.com/wp/2007/05/04/powershell-tricks-trick-2/</link>
		<comments>http://www.nazspace.com/wp/2007/05/04/powershell-tricks-trick-2/#comments</comments>
		<pubDate>Fri, 04 May 2007 17:20:52 +0000</pubDate>
		<dc:creator>nazeeh</dc:creator>
				<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://www.nazspace.com/wp/2007/05/04/powershell-tricks-trick-2/</guid>
		<description><![CDATA[So this one is quite a handy one. Do you ever find yourself wanting to jump back and forth between folders? I have quite a few folders on my system (or on the network) that I use everyday. I wanted to have a way to quickly jump to each of these folders regardless where I [...]]]></description>
			<content:encoded><![CDATA[<p>So this one is quite a handy one. Do you ever find yourself wanting to jump back and forth between folders? I have quite a few folders on my system (or on the network) that I use everyday. I wanted to have a way to quickly jump to each of these folders regardless where I am. At the same time, I wanted someway to be able to create such jump points whenever I want to.</p>
<p>The solution I came up with was to create functions that would change my location to the target folder I want to jump to. So I had a function I called &#8220;source&#8221; that would run &#8220;cd c:\source\&#8221; for instance. Then I took it one step ahead and created a function called &#8220;aliasthis&#8221; that would create such &#8220;jump&#8221; functions automatically.</p>
<p>To do that, I created a script file I called &#8220;aliases.ps1&#8243;. In it I added the following function:</p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px"><span style="color: #606060">   1:</span> <span style="color: #0000ff">function</span> aliasthis($alias)</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px"><span style="color: #606060">   2:</span> {</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px"><span style="color: #606060">   3:</span>     $path = (Get-Location).path;</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px"><span style="color: #606060">   4:</span>     <span style="color: #0000ff">if</span> ($path.substring(1,1) <span style="color: #cc6633">-eq</span> <span style="color: #006080">':'</span>)</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px"><span style="color: #606060">   5:</span>     {</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px"><span style="color: #606060">   6:</span>         $drive = $path.substring(0,2);</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px"><span style="color: #606060">   7:</span>         $<span style="color: #0000ff">script</span> = <span style="color: #006080">"$drive ; cd `"</span>$path`<span style="color: #006080">""</span>;</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px"><span style="color: #606060">   8:</span>     }</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px"><span style="color: #606060">   9:</span>     <span style="color: #0000ff">else</span></pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px"><span style="color: #606060">  10:</span>     {</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px"><span style="color: #606060">  11:</span>         $<span style="color: #0000ff">script</span> = <span style="color: #006080">"cd `"</span>$path`<span style="color: #006080">""</span></pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px"><span style="color: #606060">  12:</span>     }</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px"><span style="color: #606060">  13:</span></pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px"><span style="color: #606060">  14:</span>     $<span style="color: #0000ff">function</span> = <span style="color: #006080">"function global:$alias { $script }"</span>;</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px"><span style="color: #606060">  15:</span>     add-content $env:psconfig\\myscripts\\aliases.ps1 $<span style="color: #0000ff">function</span></pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px"><span style="color: #606060">  16:</span>     new-item <span style="color: #0000ff">function</span>:<span style="color: #0000ff">global</span>:$alias -value <span style="color: #006080">"$script"</span>;</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px"><span style="color: #606060">  17:</span> }</pre>
<p>To use that function, you type &#8220;aliasthis &lt;aliasname&gt;&#8221; and it will create a function with the name you specified that will take you to the location you ran the function from. So if you run it like this:</p>
<p>PS:c:\source&gt; aliasthis source</p>
<p>It will create a function called &#8220;source&#8221; that will always take you to c:\source\.<br />
The function does two things actually, it creates the function you want in the current shell session so you can use it right away, then</p>
<p>it adds the text of that function to the end of the aliases.ps1 file so that next time you start the shell, the function is available. So at the end of my aliases.ps1 file, I have stuff like:</p>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px"><span style="color: #0000ff">function</span> <span style="color: #0000ff">global</span>:desktop { C: ; cd <span style="color: #006080">"C:Users\nazeehe\Desktop"</span> }</pre>
<p>Last, I make a call to aliases.ps1 from my profile.ps1 script to make sure this file gets loaded with every instance of the shell:<br />
. aliases.ps1</p>
<p>That&#8217;s it! Works like a charm. I have quite a bit of jump functions declared now and I can make my way to any place on my PC or the network with just a few keystrokes!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nazspace.com/wp/2007/05/04/powershell-tricks-trick-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PowerShell Tricks &#8211; Trick 1</title>
		<link>http://www.nazspace.com/wp/2007/05/03/powershell-tricks-trick-1/</link>
		<comments>http://www.nazspace.com/wp/2007/05/03/powershell-tricks-trick-1/#comments</comments>
		<pubDate>Thu, 03 May 2007 23:39:28 +0000</pubDate>
		<dc:creator>nazeeh</dc:creator>
				<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://www.nazspace.com/wp/2007/05/03/powershell-tricks-trick-1/</guid>
		<description><![CDATA[Man I love Powershell! Finally there&#8217;s a shell on Windows that actually kicks major ass! I decided to start a series of Powershell tricks that I&#8217;ve learned. This one here is the first one :)
This first one is a simple piece of code in my profile.ps1 file that detects whether the shell is running as [...]]]></description>
			<content:encoded><![CDATA[<p>Man I love <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx">Powershell</a>! Finally there&#8217;s a shell on Windows that actually kicks major ass! I decided to start a series of Powershell tricks that I&#8217;ve learned. This one here is the first one :)</p>
<p>This first one is a simple piece of code in my profile.ps1 file that detects whether the shell is running as admin or not. If the shell is running as admin, it gets a red background to make that very clear:</p>
<p><a atomicselection="true" href="http://www.nazspace.com/wp/wp-content/uploads/2007/05/windowslivewriterpowershelltrickstrick1-e8a1image1.png"><img border="0" width="640" src="http://www.nazspace.com/wp/wp-content/uploads/2007/05/windowslivewriterpowershelltrickstrick1-e8a1image-thumb1.png" height="479" style="border-width: 0px" /></a></p>
<p>To do that, edit your profile.ps1 file (or create it in a folder called WindowsPowershell in your Documents folder). The code I use to detect admin user or not is:</p>
<pre class="csharpcode">$wid=[System.Security.Principal.WindowsIdentity]::GetCurrent()
$prp=new-object System.Security.Principal.WindowsPrincipal($wid)
$adm=[System.Security.Principal.WindowsBuiltInRole]::Administrator
$IsAdmin=$prp.IsInRole($adm)
<span class="kwrd">if</span> ($IsAdmin)
{
  (get-host).UI.RawUI.Backgroundcolor=<span class="str">"DarkRed"</span>
  clear-host
}</pre>
<pre class="csharpcode"></pre>
<style type="text/css">  .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } </style>
<p>This will cause the shell to have a DarkRed background if you&#8217;re admin, otherwise it will be the default blue color.</p>
<p>The $IsAdmin variable is then defined throughout the script, so you can use it for any other customization such as the prompt:</p>
<pre class="csharpcode"><span class="kwrd">function</span> prompt
{
    <span class="kwrd">if</span> ($IsAdmin)
    {
        Write-Host (<span class="str">"PS (Admin) "</span> + $pwd +<span class="str">"&gt;"</span>) -nonewline -foregroundcolor Green
        $host.ui.rawui.WindowTitle = <span class="str">"Admin Shell: "</span> + $(get-location)
    }
    <span class="kwrd">else</span>
    {
        Write-Host (<span class="str">"PS "</span> + $pwd +<span class="str">"&gt;"</span>) -nonewline -foregroundcolor Green
        $host.ui.rawui.WindowTitle = <span class="str">"Windows Powershell: "</span> + $(get-location)
    }
    <span class="kwrd">return</span> <span class="str">" "</span>
}</pre>
<style type="text/css">  .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } </style>
<p>That&#8217;s it! Have fun! More stuff to come soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nazspace.com/wp/2007/05/03/powershell-tricks-trick-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
