<?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>Windows Server HQ by Train Signal.com &#187; Command Shell</title>
	<atom:link href="http://windowsserver.trainsignal.com/tag/command-shell/feed" rel="self" type="application/rss+xml" />
	<link>http://windowsserver.trainsignal.com</link>
	<description>We are here to help you learn Windows Server!</description>
	<lastBuildDate>Fri, 20 Aug 2010 16:23:22 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Active Directory PowerShell Scripts Management Tool For Admins</title>
		<link>http://windowsserver.trainsignal.com/ad-powershell-scripts-management-tool</link>
		<comments>http://windowsserver.trainsignal.com/ad-powershell-scripts-management-tool#comments</comments>
		<pubDate>Wed, 21 Jul 2010 14:00:36 +0000</pubDate>
		<dc:creator>Brian Nelson</dc:creator>
				<category><![CDATA[Server 2008 R2]]></category>
		<category><![CDATA[Active Directory]]></category>
		<category><![CDATA[Active Directory Module]]></category>
		<category><![CDATA[Command Shell]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell 2.0]]></category>

		<guid isPermaLink="false">http://windowsserver.trainsignal.com/?p=7531</guid>
		<description><![CDATA[Microsoft Active Directory is at the heart of the company&#8217;s server systems. From Windows Server to Exchange Server and beyond, the power of configuring Active Directory policies and objects allows IT to manage a vast empire of resources, users, and workstations in the Enterprise computing environment. Unfortunately, all of that scalability and flexibility can quickly [...]

<h3>Related posts:<ul><li><a href='http://windowsserver.trainsignal.com/powershell-2-0-server-2008-r2' rel='bookmark' title='Permanent Link: PowerShell 2.0: Server 2008 R2 Top New Management Feature'>PowerShell 2.0: Server 2008 R2 Top New Management Feature</a></li>
<li><a href='http://windowsserver.trainsignal.com/windows-server-2008-powershell' rel='bookmark' title='Permanent Link: Take Command of Server 2008 with Windows PowerShell &#8211; Part 1'>Take Command of Server 2008 with Windows PowerShell &#8211; Part 1</a></li>
<li><a href='http://windowsserver.trainsignal.com/dont-be-afraid-of-windowspowershell' rel='bookmark' title='Permanent Link: Don’t be Afraid of PowerShell'>Don’t be Afraid of PowerShell</a></li>
</ul></h3>]]></description>
			<content:encoded><![CDATA[<p>Microsoft Active Directory is at the heart of the company&#8217;s server systems. From Windows Server to Exchange Server and beyond, the power of configuring Active Directory policies and objects allows IT to manage a vast empire of resources, users, and workstations in the Enterprise computing environment. Unfortunately, all of that scalability and flexibility can quickly add up to a high amount of complexity.</p>
<p>Simply finding the right objects and then updating their properties or implementing changes can be a cumbersome process. Many Microsoft systems engineers have developed their own shortcuts and conventions over the years for dealing with the administration of complex Active Directory structures. One tool that has been lacking, however, is the ability to write powerful scripts to manage Active Directory.</p>
<p>The good news is that the <a href="http://windowsserver.trainsignal.com/windows-2008-server-r2-update-review">arrival of Windows Server 2008 R2</a> with PowerShell 2.0 and the Active Directory Module changes all of that for the better.</p>
<h2>Powershell 2.0 and Active Directory Module</h2>
<p>Of the many <a href="http://windowsserver.trainsignal.com/server-2008-r2-sp1-dynamic-memory-remotefx">new features in Windows Server 2008 R2</a>, PowerShell 2.0 is one that may finally be coming into its own. One of the key new features in PowerShell 2.0 is the addition of modules. Modules differ from PowerShell 1.0 snap-ins in that they are self-contained and do not require registration or installation. Rather, modules are imported into the shell via the Import-Module command. Modules can also be offloaded when they are no longer needed.</p>
<p><span id="more-7531"></span><br />
To use the Active Directory Module, there needs to be at least on Windows Server 2008 R2 Domain Controller running Active Directory Web Services (ADWS) in the domain. As an alternative, the Active Directory Management Gateway Service can be installed on Windows Server 2003 SP2 servers and Windows Server 2008 (non-R2) servers with or without SP2 installed.</p>
<p>For the most powerful configuration of PowerShell 2.0 with the Active Directory Module, you will want to be able to do your scripting remotely from your own computer, or other workstation. This does require Windows 7 in order to install the Remote Server Administration Tools (RSAT).</p>
<p>The Active Directory Module provides a powerful way to manage AD structures even across domains. Part of the AD Module is the PSDrive Provider which allows you to map to an Active Directory domain using whatever credentials are required via the New-PSDrive cmdlet. Users are connected to their current domain by default. The mapped rights persist for the entire shell session, even if it requires using different login credentials for several different AD domains.</p>
<h2>Active Directory Scripts In PowerShell 2.0</h2>
<p>There are many different commands included in the Active Directory Module. One count places the total number of new commands at 82. The most commonly used commands, however, are those that match up with the most common Windows Server Administrator tasks. The naming convention for Active Directory cmdlets dictates that each cmdlet start with &#8220;AD&#8221; in order to help separate the Active Directory versions from similar PowerShell cmdlets available in the base PowerShell.</p>
<p>Thanks to this naming convention, obtaining a list of all the Active Directory Module cmdlets can be done by running the Help *-AD* command.</p>
<p>The most difficult part of getting up to speed with Active Directory management via PowerShell 2.0 is mastering all of the parameters available for each cmdlet. In an effort to allow virtually any function that can be performed manually to be scripted, Microsoft had to provide a working parameter for pretty much every setting, checkbox, and field that there is in the GUI. That means that some commands have a mind boggling array of available options. Fortunately, only a small subset of any cmdlet&#8217;s parameters are mandatory in order to run the desired command.</p>
<p>As with any new programming language, the key is to focus in the beginning on the basics and most frequently used options and build mastery as you go along. While it may seem daunting at first, one will quickly find that using built-in cmdlets specifically designed for their purpose ends up being much easier to both code and manage than mastering all of the work-arounds and band-aids currently required to perform the same tasks.</p>
<h2>Common Active Directory Cmdlets for PowerShell</h2>
<p>The most common administrative tasks within Active Directory are those that relate to creating, finding, and changing objects and users. Not surprisingly, these cmdlets make a great place to start learning and using PowerShell 2.0 to manage Active Directory.</p>
<p><strong>Commonly used PowerShell AD cmdlets include:</strong></p>
<ul>
<li>New-ADUser</li>
<p></p>
<li>New-ADGroup</li>
<p></p>
<li>New-ADComputer</li>
<p></p>
<li>New-ADOrganization</li>
<p></p>
<li>New-ADServiceAccount</li>
<p></p>
<li>Unlock-ADAccount</li>
<p></p>
<li>Enable-ADAccount</li>
<p></p>
<li>Disable-ADAccount</li>
<p></p>
<li>Get-ADUser</li>
<p></p>
<li>Add-ADGroupMember</li>
<p></p>
<li>Get-ADGroupMember</li>
<p></p>
<li>Get-ADForest</li>
<p></p>
<li>Get-ADDomain</li>
<p></p>
<li>Get-ADDomainController</li>
</ul>
<p>Of course, the real power from scripting comes not from typing in a bunch of esoteric computer commands instead of clicking mouse buttons, but from the ability to save useful scripts and use them over and over again. To this end, Active Directory cmdlets support piping information into the cmdlets. For example, to create a couple dozen new users, the administrator could take the Excel Spreadsheet supplied from Human Resources, export it as a CSV file and then pipe the resulting data to the New-ADUser command: <em>Import-CSV c:\neweuserdata\april-new-employees.csv | New-ADUser</em> and let the script take care of all the basic data entry.</p>
<p>Using parts of the same file, the admin can go back through and using the appropriate cmdlets add users to their respective groups and domains and even apply additional group policies to the new users.</p>
<p>Of course, easy, but highly repetitive tasks can be automated as well. Imagine picking up the phone with a call from a panicked user who has locked himself out of his account (again). A tiny shortcut launched directly with minimal typing and clicking requiring nothing more than the user&#8217;s login name quickly firing off and unlocking or even re-enabling the account, all without ever having to leave the screen you were already working on when the phone rang.</p>
<h2>PowerShell Resources</h2>
<p>Even though the Active Directory Module is new with PowerShell 2.0 there are already some great references available for Microsoft server administrators. Check out Jonathan Medd&#8217;s <a href="http://www.jonathanmedd.net/wp-content/uploads/2009/10/ADPowerShell_QuickReference.pdf">Active Directory PowerShell Quick Reference Guide</a> for help getting up to speed and remembering lesser used commands. Microsoft has a general <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=DF8ED469-9007-401C-85E7-46649A32D0E0&amp;displaylang=en">PowerShell Quick Reference guide</a> as well. For those of you lamenting the hours spent mastering VBScripting, check out the <a href="http://technet.microsoft.com/en-us/library/ee221101.aspx">VBScript to Windows PowerShell Conversion Guide</a>.</p>
<p>Learning new technology and skills is never easy, but the truth &#8212; if we are willing to admit it &#8212; is that as high-tech computer administrators, we quickly grow bored with doing the same things over and over again. Not only does PowerShell 2.0 and the Active Directory Module provide some new material for the skills menu, it also provides a way to eliminate far more tedious, repetitive tasks than ever before.</p>


<h3>Related posts:<ul><li><a href='http://windowsserver.trainsignal.com/powershell-2-0-server-2008-r2' rel='bookmark' title='Permanent Link: PowerShell 2.0: Server 2008 R2 Top New Management Feature'>PowerShell 2.0: Server 2008 R2 Top New Management Feature</a></li>
<li><a href='http://windowsserver.trainsignal.com/windows-server-2008-powershell' rel='bookmark' title='Permanent Link: Take Command of Server 2008 with Windows PowerShell &#8211; Part 1'>Take Command of Server 2008 with Windows PowerShell &#8211; Part 1</a></li>
<li><a href='http://windowsserver.trainsignal.com/dont-be-afraid-of-windowspowershell' rel='bookmark' title='Permanent Link: Don’t be Afraid of PowerShell'>Don’t be Afraid of PowerShell</a></li>
</ul></h3>]]></content:encoded>
			<wfw:commentRss>http://windowsserver.trainsignal.com/ad-powershell-scripts-management-tool/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Don’t be Afraid of PowerShell</title>
		<link>http://windowsserver.trainsignal.com/dont-be-afraid-of-windowspowershell</link>
		<comments>http://windowsserver.trainsignal.com/dont-be-afraid-of-windowspowershell#comments</comments>
		<pubDate>Sat, 01 Aug 2009 00:00:54 +0000</pubDate>
		<dc:creator>Lisa Szpunar</dc:creator>
				<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[Command Shell]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell Scripting]]></category>
		<category><![CDATA[Server Admin]]></category>

		<guid isPermaLink="false">http://windowsserver.trainsignal.com/?p=6626</guid>
		<description><![CDATA[What is PowerShell?
PowerShell is Microsoft’s newish extensible scripting language and corresponding command line shell. PowerShell was specifically made for IT professionals to achieve greater productivity and control system administration more easily. 
What PowerShell Can Help You Do
The thing is, PowerShell can do pretty much anything except walk your dog for you. You can even check the [...]

<h3>Related posts:<ul><li><a href='http://windowsserver.trainsignal.com/windows-server-2008-powershell' rel='bookmark' title='Permanent Link: Take Command of Server 2008 with Windows PowerShell &#8211; Part 1'>Take Command of Server 2008 with Windows PowerShell &#8211; Part 1</a></li>
<li><a href='http://windowsserver.trainsignal.com/ad-powershell-scripts-management-tool' rel='bookmark' title='Permanent Link: Active Directory PowerShell Scripts Management Tool For Admins'>Active Directory PowerShell Scripts Management Tool For Admins</a></li>
<li><a href='http://windowsserver.trainsignal.com/windows-server-2008-powershell-2' rel='bookmark' title='Permanent Link: Take Command of Server 2008 with Windows PowerShell &#8211; Part 2'>Take Command of Server 2008 with Windows PowerShell &#8211; Part 2</a></li>
</ul></h3>]]></description>
			<content:encoded><![CDATA[<h2>What is PowerShell?</h2>
<p>PowerShell is Microsoft’s newish extensible scripting language and corresponding command line shell. PowerShell was specifically made for IT professionals to achieve greater productivity and control system administration more easily. </p>
<h2>What PowerShell Can Help You Do</h2>
<p>The thing is, PowerShell can do pretty much anything except walk your dog for you. You can even check the date and time if you really wanted to. I guess you could stop using the command line all together and do all your cmd tasks from within the PowerShell shell. </p>
<p>However, the real fun comes in when you can use PowerShell to make your sysadmin life easier. Here are a few random examples:</p>
<ul>
<li>Inventory your servers like what each has, the free memory, what service pack it is running, and so on.</li>
<p></p>
<li>Add multiple users at once to your AD and then give them all a mailbox in Exchange.</li>
<p></p>
<li>Back up and sync certain files then email yourself a corresponding log file&#8230;every night.</li>
<p></p>
<li>Test out those scary commands before committing to them using the <em>Whatif</em> feature.</li>
<p></p>
<li>And maybe the most compelling thing: You know how in Server 2008 R2 you can recover an AD object from the recycle bin after you have – oops – deleted it? Well you won’t find that option anywhere in the GUI. You need PowerShell to do it. If that isn’t a reason to give PowerShell a try then I don’t know what is!</li>
</ul>
<p><span id="more-6626"></span></p>
<h2>For the Newbies</h2>
<p>Good News! You don’t need any prior programming experience to use PowerShell &#8212; it is that intuitive. But, just so we are on the same page here is a short vocab lesson:</p>
<ul>
<li><strong>Shell</strong> – What you the user actually interacts with. Either a command line or a GUI (graphical user interface).</li>
<p></p>
<li><strong>Extensible</strong> – The ability of a system to grow and change as needed.</li>
<p></p>
<li><strong>Scripting Language</strong> – Well, there are numerous debates going on all over creation about the difference between a programming language and a scripting language. You don’t really need to understand the specifics to understand that PowerShell is a language that you use to do administrative tasks. Who cares whether it is interpreted or compiled?</li>
<p></p>
<li><strong>cmdlets</strong> – Pronounced <em>command-lets</em>. Cmdlets are simple tools that can be used separately, but their power is realized when you combine these simple tools to perform complex tasks. Microsoft provides buckets of built-in cmdlets  but you can write your own if you see fit.</li>
</ul>
<h2>For the People with Programming or Unix Experience</h2>
<p>Not surprisingly PowerShell has all the comforts of home: man pages, aliases, wildcards, and pipelines; if statements, recursion, and loops.</p>
<p>If you have worked with VB or WHS then you should be able to make the translation pretty easily. There is even <a title="The VBScript-to-Windows PowerShell Conversion Guide" href="http://www.microsoft.com/technet/scriptcenter/topics/winpsh/convert/default.mspx" target="_blank">help for translating your existing VB scripts to PowerShell</a>.</p>
<h2>PowerShell Resources to Get You Started</h2>
<ol>
<li><a title="Take Command of Server 2008 with Windows PowerShell" href="http://windowsserver.trainsignal.com/windows-server-2008-powershell">Take Command of Server 2008 with PowerShell</a> &#8212; a short series of articles that provide a good introduction to PowerShell</li>
<p></p>
<li><a title="PowerShell FAQ" href="http://www.microsoft.com/windowsserver2008/en/us/powershell-faq.aspx">PowerShell FAQ</a> provided by Microsoft </li>
<p></p>
<li><a title"Professor PowerShell" href="http://mcpmag.com/articles/list/prof-powershell.aspx">Professor PowerShell</a> Jeff Hick&#8217;s educational column on MCPmag.com</a></li>
<p></p>
<li><a title="Windows PowerShell Owners Manual" href="http://www.microsoft.com/technet/scriptcenter/topics/winpsh/manual/default.mspx">Windows PowerShell Owners Manual</a> a free guide to getting started with PowerShell</li>
<p></p>
<li><a title="Scripting with Windows PowerShell" href="http://technet.microsoft.com/en-us/scriptcenter/dd742419.aspx">Scripting with Windows PowerShell</a> a list of resources for sysadmins interested in learning about PowerShell</li>
<p></p>
<li><a title="Windows PowerShell Blog" href="http://blogs.msdn.com/powershell/default.aspx">Windows PowerShell Blog</a> with information about the latest advancements in PowerShell</li>
<p></p>
<li><a title="Windows PowerShell Cookbook" href="http://www.amazon.com/Windows-PowerShell-Cookbook-Scripting-Microsofts/dp/0596801505/ref=sr_1_1?s=books&#038;ie=UTF8&#038;qid=1282320870&#038;sr=1-1">Windows PowerShell Cookbook</a> providing you with recipes to do specific tasks with PowerShell.</li>
<p></p>
<li><a href="http://www.amazon.com/Windows-PowerShell-2-0-Don-Jones/dp/0982131429">Windows PowerShell 2.0</a> will teach you just about everything you ever wanted to know about PowerShell (and more)</li>
</ol>
<h2> Good luck!</h2>


<h3>Related posts:<ul><li><a href='http://windowsserver.trainsignal.com/windows-server-2008-powershell' rel='bookmark' title='Permanent Link: Take Command of Server 2008 with Windows PowerShell &#8211; Part 1'>Take Command of Server 2008 with Windows PowerShell &#8211; Part 1</a></li>
<li><a href='http://windowsserver.trainsignal.com/ad-powershell-scripts-management-tool' rel='bookmark' title='Permanent Link: Active Directory PowerShell Scripts Management Tool For Admins'>Active Directory PowerShell Scripts Management Tool For Admins</a></li>
<li><a href='http://windowsserver.trainsignal.com/windows-server-2008-powershell-2' rel='bookmark' title='Permanent Link: Take Command of Server 2008 with Windows PowerShell &#8211; Part 2'>Take Command of Server 2008 with Windows PowerShell &#8211; Part 2</a></li>
</ul></h3>]]></content:encoded>
			<wfw:commentRss>http://windowsserver.trainsignal.com/dont-be-afraid-of-windowspowershell/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Take Command of Server 2008 with Windows PowerShell &#8211; Part 4</title>
		<link>http://windowsserver.trainsignal.com/windows-server-2008-powershell-4</link>
		<comments>http://windowsserver.trainsignal.com/windows-server-2008-powershell-4#comments</comments>
		<pubDate>Thu, 21 Feb 2008 16:30:48 +0000</pubDate>
		<dc:creator>Jason Ensinger</dc:creator>
				<category><![CDATA[Server 2008]]></category>
		<category><![CDATA[cmdlets]]></category>
		<category><![CDATA[Command Prompt]]></category>
		<category><![CDATA[Command Shell]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell Scripting]]></category>

		<guid isPermaLink="false">http://www.trainsignaltraining.com/windows-server-2008-powershell-4/2008-02-21/</guid>
		<description><![CDATA[In the last couple of weeks you were introduced to the basics of Windows PowerShell, Microsoft&#8217;s new command shell environment.
In Part 1 I talked about what PowerShell is and showed you how to install and access it on Windows Server 2008.
In Part 2 we went over PowerShell cmdlets and PowerShell providers. I showed you how [...]

<h3>Related posts:<ul><li><a href='http://windowsserver.trainsignal.com/windows-server-2008-powershell-2' rel='bookmark' title='Permanent Link: Take Command of Server 2008 with Windows PowerShell &#8211; Part 2'>Take Command of Server 2008 with Windows PowerShell &#8211; Part 2</a></li>
<li><a href='http://windowsserver.trainsignal.com/windows-server-2008-powershell-3' rel='bookmark' title='Permanent Link: Take Command of Server 2008 with Windows PowerShell &#8211; Part 3'>Take Command of Server 2008 with Windows PowerShell &#8211; Part 3</a></li>
<li><a href='http://windowsserver.trainsignal.com/windows-server-2008-powershell' rel='bookmark' title='Permanent Link: Take Command of Server 2008 with Windows PowerShell &#8211; Part 1'>Take Command of Server 2008 with Windows PowerShell &#8211; Part 1</a></li>
</ul></h3>]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.trainsignaltraining.com/wpnew/wp-content/uploads/2008/01/PowerShell2.jpg" alt="Windows PowerShell" title="Windows PowerShell" align="right" width="251" height="200" border="0" />In the last couple of weeks you were introduced to the basics of <strong>Windows PowerShell</strong>, Microsoft&#8217;s new command shell environment.</p>
<p>In <a href="http://windowsserver.trainsignal.com/windows-server-2008-powershell"><strong>Part 1</strong></a> I talked about what PowerShell is and showed you how to install and access it on Windows Server 2008.</p>
<p>In <a href="http://windowsserver.trainsignal.com/windows-server-2008-powershell-2"><strong>Part 2</strong></a> we went over PowerShell cmdlets and PowerShell providers. I showed you how to execute cmdlets and work with the objects returned and also how to use the different PowerShell providers to work with server resources inaccessible from the FileSystem provider.</p>
<p>In <a href="http://windowsserver.trainsignal.com/windows-server-2008-powershell-3/"><strong>Part 3</strong></a> we learned how to customize the user interface with the PowerShell profile.</p>
<p>And now that you are familiar with the capabilities of PowerShell, it is time to learn how to really unleash the power of PowerShell with PowerShell scripting.</p>
<p>Today I&#8217;ll show you how to take advantage of the script engine to automate the performance of Administrative tasks on the Server.</p>
<p><span id="more-423"></span></p>
<h3>Understanding PowerShell Scripting</h3>
<p>If you followed along with the PowerShell customization exercise that I showed you in <a href="http://windowsserver.trainsignal.com/windows-server-2008-powershell-3">the last article</a>, you already know how to create PowerShell scripts. The profile file created in that exercise is actually a PowerShell Script.</p>
<p>In essence, a PowerShell script is simply a text file containing a list of PowerShell commands saved with the file extension .ps1.</p>
<p>For security purposes, script execution is disabled by default. You can set the script execution policy with the <code>Set-ExecutionPolicy</code> cmdlet.</p>
<p>The parameters available for the <code>Set-ExecutionPolicy</code> cmdlet are: <code>-restricted</code>, <code>-unrestricted</code>, <code>-remotesigned</code> and <code>–allsigned</code>. Enter the command: <code>Get-Help Set-ExecutionPolicy –detailed</code> for details on the <code>Set-ExecutionPolicy</code> cmdlet parameters.</p>
<p>In order to exhibit the capabilities of the PowerShell script engine we will go over a sample PowerShell script. The example script was created to display the potential of PowerShell scripting for performing administrative tasks in a server environment.</p>
<p>When the example script is ran, it behaves like a program. It first lists all the printers installed on the server and then prompts you to select one or all of the printers.</p>
<p>Once a printer is selected an additional menu is displayed for operations that can be performed with the printer or printers. When an action is selected, it is performed, then the program begins again at the beginning until you enter ‘exit’ at one of the prompts.</p>
<p>If we examine the script, we can see that it is broken up into three sections. The first section is dedicated to the function definition portion of the script. The second section covers the process of prompting the user. The third section is where the operation chosen is performed on the selected printer.</p>
<pre>
function cancelPrinterJobs {
	$objPrinter = $args[0]
	$objCancel = $objPrinter.CancelAllJobs()
	if ($objCancel.ReturnValue -eq 0) {
		write-host "Cancelled all jobs on"$objPrinter.Name
	}
	else {
		write-host "Cancel of all jobs on"$objPrinter.Name"failed"
	}
}

function pausePrinter {
	$objPrinter = $args[0]
	$objPause = $objPrinter.Pause()
	if ($objPause.ReturnValue -eq 0) {
		write-host $objPrinter.Name"pause"
	}
	else {
		write-host "Pause of"$objPrinter.Name"failed"
	}
}

function resumePrinter {
	$objPrinter = $args[0]
	$objResume = $objPrinter.Resume()
	if ($objResume.ReturnValue -eq 0) {
		write-host $objPrinter.Name" resumed"
	}
	else {
		write-host "Resume of"$objPrinter.Name"failed"
	}
}

function testPrinter {
	$objPrinter = $args[0]
	$objTest = $objPrinter.PrintTestPage()
	if ($objTest.ReturnValue -eq 0) {
		write-host $objPrinter.Name" printed a test page"
	}
	else {
		write-host $objPrinter.Name" test page failed"
	}
}

function setDefaultPrinter {
	$objPrinter = $args[0]
	$objDefault = $objPrinter.SetDefaultPrinter()
	if ($objDefault.ReturnValue -eq 0) {
		write-host $objPrinter.Name" Set as default."
	}
	else {
		write-host "Failed to set"$objPrinter.Name"as default"
	}
}

function writePrinterInfo {
	$objPrinter = $args[0]
	$strComputerName = $args[1]
	$colPrinters = get-wmiobject -class "Win32_PrinterConfiguration" -namespace "root\CIMV2" -computername $strComputerName

	write-host $objPrinter.Name "Printer Information"
	write-host
	write-host "Name: " $objPrinter.Name
	write-host "Driver Name: " $objPrinter.DriverName
	write-host "Port Name: " $objPrinter.PortName
	write-host "Shared: " $objPrinter.Shared
	write-host "Share Name: " $objPrinter.ShareName
	write-host "Queued: " $objPrinter.Queued
	write-host "Status: " $objPrinter.Status

	foreach ($objPrinter in $colPrinters) {
		if ($objPrinter.Name -eq $strPrinterName) {
			write-host "Driver Version: " $objPrinter.DriverVersion
			write-host "Paper Size: " $objPrinter.PaperSize
			write-host "X Resolution: " $objPrinter.XResolution
			write-host "Y Resolution: " $objPrinter.YResolution
			write-host
			break
		}
	}
}
</pre>
<p>In the first section, six functions are defined. Each function performs an action with a printer. The function cmdlet is used to define each function. Immediately after the <code>function</code> cmdlet the function name is supplied, followed by the commands of the function enclosed in curly brackets.</p>
<p>Functions in PowerShell do not support defining the arguments. Instead, functions accept a virtually unlimited number of space-separated objects as arguments. The arguments can be accessed within the function with the $args variable.</p>
<p>When PowerShell executes a script, commands are executed as the script is read rather than loaded to memory and then executed. Therefore, a function must be defined in the script before it is ever called.</p>
<p>It is a good idea to always define all your functions first in a PowerShell script. If a function is called within another function the called function must be defined first.</p>
<p>The first commands of every function are to assign the expected argument to a variable for script readability. All the functions expect a WMI Printer object as the first argument. Only the last function expects a second argument, the computer name.</p>
<p>The first five functions each execute a method of the printer object and assign it to a variable. The return value is checked for successful execution with an &#8220;if&#8221; statement and if the conditions in the parentheses are met the <code>Write-Host</code> cmdlet in the curly brackets is executed to display a success message.</p>
<p>If the successful condition is not met a failure message is displayed from the command in the curly brackets of the else statement.</p>
<p>After the argument variables are assigned in the final function the <code>Get-WMIObject</code> cmdlet is used to assign the Win32_PrinterConfiguration object to a variable. Then select properties from the supplied Printer object are displayed.</p>
<p>After that the <code>Foreach-Object</code> cmdlet is used to loop through the items of the PrinterConfiguration object then checks if its name matches that of the Printer object supplied to the function. When a match is found select properties from the PrinterConfiguration object are displayed and the loop is exited with the <code>break</code> cmdlet.</p>
<pre>
cls

$strComputerName = "."
$colPrinters = get-wmiobject -class "Win32_Printer" -namespace "root\CIMV2" -computername $strComputerName | sort-object "Name"

do {
	$printerIndex = 0
	write-host
	write-host "Installed Printers"
	write-host
	write-host "0) All Printers"

	foreach ($objPrinter in $colPrinters) {
		$printerIndex = $printerIndex + 1
		write-host $printerIndex") "$objPrinter.Name
	}

	write-host

	$selectedPrinterIndex = read-host "Select the printer(s) you wish to work with or type 'exit' to exit"
	if ($selectedPrinterIndex -eq "exit") {
		break
	}
	$validated = 0
	do {
		if ($selectedPrinterIndex -gt $printerIndex) {
			$selectedPrinterIndex = read-host "Please enter a valid printer number"
		}
		else {	$validated = 1 }
	}
	while ($validated -lt 1)

	write-host
	write-host "Printer Operations"
	write-host
	write-host "0) Display Printer(s) Information"
	write-host "1) Cancel Printer(s) Jobs"
	write-host "2) Pause Printer(s)"
	write-host "3) Resume Printer(s)"
	write-host "4) Test Printer(s)"
	if ($selectedPrinterIndex -gt 0) {
		write-host "5) Set Printer As Default"
	}
	write-host

	$selectedOperationIndex = read-host "Select an action to perform on the printer or type 'exit' to exit"
	if ($selectedOperationIndex -eq "exit") {
		break
	}
	$validated = 0
	do {
		if ($selectedOperationIndex -gt 5) {
			$selectedOperationIndex = read-host "Please enter a valid operation number"
		}
		else {
			if ($selectedPrinterIndex -eq 0) {
				if ($selectedOperationIndex -eq 5) {
					$selectedOperationIndex = read-host "Please enter a valid operation number"
				}
				else {	$validated = 1 }
			}
			else {	$validated = 1 }
		}
	}
	while ($validated -lt 1)
</pre>
<p>The second section of the script is where execution begins. The program begins by clearing the console with the <code>cls</code> cmdlet. Next a variable is assigned with the computer name.</p>
<p>When a computer name is expected as a cmdlet parameter the dot used will be interpreted as the local machine. The computer name variable is then used when assigning the WMI Win32_Printer object to a variable.</p>
<p>The <code>DoWhile-Object</code> is executed next and is closed at the end of the script with <code>while (1)</code>. This tells the program to loop execution until the loop is exited with the <code>break</code> cmdlet.</p>
<p>The next four commands display the printer menu title and first option as 0 for selecting all printers. A variable is then created to keep track of the printer index before the <code>foreach-object</code> cmdlet is used to loop through the Printer objects of the Win32_Printer object. Each time through the loop one is added to the printer index then it is displayed with the name of the current Printer object.</p>
<p>After the loop a blank line is displayed to separate the menu items from the prompt. The prompt is displayed with the <code>Read-Host</code> cmdlet and the input is assigned to a variable to represent the index of the selected printer. The printer index variable is then checked if the value is exit and exits the main program loop if so.</p>
<p>A variable is then assigned the value of 0 to represent the input has not been validated. A Do While loop is set to loop until the validation variable equals 1. Enclosed in the loop is an if object that is used to check if the printer index exceeds the number of printers, if so, If the input is invalid the script prompts again for a valid printer index until a valid input is provided by the user.</p>
<p>The second menu is then displayed. An &#8220;if&#8221; statement is used to check if the printer index variable is greater than 0 before the operation to set as the default printer is displayed.</p>
<p>The user is then prompted to enter an operation. Validation for the second menu is done using the same logic as the first menus validation. The difference is an &#8220;if&#8221; statement to check to make sure the operation index supplied is not to set all printers to default.</p>
<pre>
	if ($selectedPrinterIndex -gt 0) {
		$objPrinter = $colPrinters[$selectedPrinterIndex - 1]
	}

	write-host
	switch ($selectedOperationIndex) {
		0 {
			if ($selectedPrinterIndex -eq 0) {
				foreach ($objPrinter in $colPrinters) {
					writePrinterInfo $objPrinter $strComputerName
				}
			}
			else {	writePrinterInfo $objPrinter $strComputerName }
		}
		1 {
			if ($selectedPrinterIndex -eq 0) {
				foreach ($objPrinter in $colPrinters) {
					cancelPrinterJobs $objPrinter
				}
			}
			else {	cancelPrinterJobs $objPrinter }
		}
		2 {
			if ($selectedPrinterIndex -eq 0) {
				foreach ($objPrinter in $colPrinters) {
					pausePrinter $objPrinter
				}
			}
			else {	pausePrinter $objPrinter }
		}
		3 {
			if ($selectedPrinterIndex -eq 0) {
				foreach ($objPrinter in $colPrinters) {
					resumePrinter $objPrinter
				}
			}
			else {	resumePrinter $objPrinter }
		}
		4 {
			if ($selectedPrinterIndex -eq 0) {
				foreach ($objPrinter in $colPrinters) {
					testPrinter $objPrinter
				}
			}
			else {	testPrinter $objPrinter }
		}
		5 {
			setDefaultPrinter $objPrinter
		}
	}
}
while (1)
cls
</pre>
<p>The final section of the script handles performing the selected operation with the selected printer or printers. It starts off by assigning the selected printer object to a variable using the selected printer index if the user did not select all printers.</p>
<p>The control of which operation is to be executed is handled by the Switch cmdlet. Within the curly brackets of the <code>Switch</code> cmdlet the commands executed are the commands within the curly brackets of the number in the <code>Switch</code> cmdlet that match the operation index provided by the user.</p>
<p>In all cases but the last, an if statement is used to check if the selected operation is to be performed on all printers. If all printers have been selected a foreach loop is used to pass all the Printer objects to the proper function otherwise only the Printer object of the selected printer is passed to the function.</p>
<p>The fifth case does not check if all printers were selected because the input validation prevents the option from being able to be selected if all printers are selected. After the switch statement the program’s infinite Do While loop is closed off the screen cleared and execution of the script ends.</p>
<p>Now that you are so familiar with how to create dynamic PowerShell scripts, you probably want to know how to execute a script. To demonstrate, go ahead and copy the commands from all three sections of the script example into notepad and save it to ‘C:\PrinterOperations.ps1’. From PowerShell enter the command below to execute the script.</p>
<pre>
&#038; “C:\PrinterOperations.ps1”
</pre>
<p>With the command above, variable names and functions used in the script will be destroyed when execution completes. If you wish to have script variables and functions available within PowerShell after the script has finished executing you can use dot-sourcing.</p>
<p>The command below will run the script and when execution completes you will have access to the variables and functions created will still be available.</p>
<pre>
&#038; . “C:\PrinterOperations.ps1”
</pre>
<p>I hope that you&#8217;ve enjoyed reading my series on Windows PowerShell.</p>
<p>Keep in mind that there are many additional resources and a number of informative references available on this topic. The owner&#8217;s manual, articles, and many useful scripting examples are available at <a href="http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx">Microsoft TechNet’s Script Center.</a></p>


<h3>Related posts:<ul><li><a href='http://windowsserver.trainsignal.com/windows-server-2008-powershell-2' rel='bookmark' title='Permanent Link: Take Command of Server 2008 with Windows PowerShell &#8211; Part 2'>Take Command of Server 2008 with Windows PowerShell &#8211; Part 2</a></li>
<li><a href='http://windowsserver.trainsignal.com/windows-server-2008-powershell-3' rel='bookmark' title='Permanent Link: Take Command of Server 2008 with Windows PowerShell &#8211; Part 3'>Take Command of Server 2008 with Windows PowerShell &#8211; Part 3</a></li>
<li><a href='http://windowsserver.trainsignal.com/windows-server-2008-powershell' rel='bookmark' title='Permanent Link: Take Command of Server 2008 with Windows PowerShell &#8211; Part 1'>Take Command of Server 2008 with Windows PowerShell &#8211; Part 1</a></li>
</ul></h3>]]></content:encoded>
			<wfw:commentRss>http://windowsserver.trainsignal.com/windows-server-2008-powershell-4/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Take Command of Server 2008 with Windows PowerShell &#8211; Part 3</title>
		<link>http://windowsserver.trainsignal.com/windows-server-2008-powershell-3</link>
		<comments>http://windowsserver.trainsignal.com/windows-server-2008-powershell-3#comments</comments>
		<pubDate>Fri, 15 Feb 2008 16:30:43 +0000</pubDate>
		<dc:creator>Jason Ensinger</dc:creator>
				<category><![CDATA[Server 2008]]></category>
		<category><![CDATA[cmdlets]]></category>
		<category><![CDATA[Command Prompt]]></category>
		<category><![CDATA[Command Shell]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://www.trainsignaltraining.com/windows-server-2008-powershell-3/2008-02-15/</guid>
		<description><![CDATA[Welcome to part three of taking command of Server 2008 with Windows PowerShell!
You&#8217;ve made it this far, so I&#8217;m assuming you enjoyed part one, where I showed you how to install and access PowerShell, and part two, where I explained PowerShell Cmdlets and PowerShell Providers.
If you missed those two articles, I would suggest reading them [...]

<h3>Related posts:<ul><li><a href='http://windowsserver.trainsignal.com/windows-server-2008-powershell-2' rel='bookmark' title='Permanent Link: Take Command of Server 2008 with Windows PowerShell &#8211; Part 2'>Take Command of Server 2008 with Windows PowerShell &#8211; Part 2</a></li>
<li><a href='http://windowsserver.trainsignal.com/windows-server-2008-powershell' rel='bookmark' title='Permanent Link: Take Command of Server 2008 with Windows PowerShell &#8211; Part 1'>Take Command of Server 2008 with Windows PowerShell &#8211; Part 1</a></li>
<li><a href='http://windowsserver.trainsignal.com/windows-server-2008-powershell-4' rel='bookmark' title='Permanent Link: Take Command of Server 2008 with Windows PowerShell &#8211; Part 4'>Take Command of Server 2008 with Windows PowerShell &#8211; Part 4</a></li>
</ul></h3>]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.trainsignaltraining.com/wpnew/wp-content/uploads/2008/01/PowerShell2.jpg" alt="Windows Power Shell" title="Windows Power Shell" align="right" width="251" height="200" border="0" />Welcome to part three of taking command of Server 2008 with Windows PowerShell!</p>
<p>You&#8217;ve made it this far, so I&#8217;m assuming you enjoyed <a href="http://windowsserver.trainsignal.com/windows-server-2008-powershell"><strong>part one</strong></a>, where I showed you how to install and access PowerShell, and <a href="http://windowsserver.trainsignal.com/windows-server-2008-powershell-2"><strong>part two</strong></a>, where I explained PowerShell Cmdlets and PowerShell Providers.</p>
<p>If you missed those two articles, I would suggest reading them first &#8212; just to make sure you&#8217;ve got all the basics. Now let&#8217;s get started with an exercise in customizing your Windows PowerShell.</p>
<h3>Customizing Windows PowerShell</h3>
<p>Windows PowerShell starts with the same look and feel of the Command Prompt, by default. Let’s make our first exercise of PowerShell power be to customize the PowerShell console.</p>
<p><span id="more-417"></span></p>
<p>The steps below will walk you through customizing the console options then saving those settings to be used every time PowerShell is launched.</p>
<p><strong>1.</strong> Open Windows PowerShell</p>
<p><strong>2.</strong> Create a variable to the PowerShell RawUI object with the command below:</p>
<blockquote>
<pre>
$psui = (get-host).UI.RawUI
</pre>
</blockquote>
<p><strong>3.</strong> Use the $psui variable to change the background and text colors with the commands below:</p>
<blockquote>
<pre>
$psui.WindowTitle = “PowerShell PowerStation”
$psui.BackGroundColor = “Blue”
$psui.ForeGroundColor = “Yellow”
</pre>
</blockquote>
<blockquote><p>
<strong>Note:</strong> The PowerShell console supports 16 colors. They are; Black, White, Blue, Cyan, Gray, Green, Magenta, Red, Yellow, DarkBlue, DarkCyan, DarkGray, DarkGreen, DarkMagenta, DarkRed and DarkYellow.
</p></blockquote>
<p><strong>4.</strong> Use the cls command to clear the console and fill the console with the background color specified</p>
<p><strong>5.</strong> View the other properties available to the object by entering $psui</p>
<blockquote><p>
<strong>Note:</strong> If you wish to change RawUI objects with multiple properties such as the BufferSize property you must assign the property to another variable to modify the object’s properties like the example below:</p>
<pre>
$psbs = $psui.BufferSize
$psbs.Height = 3000
$psbs.Width = 120
</pre>
</blockquote>
<p><strong>6.</strong> Decide on how you want to customize the PowerShell console with the properties available</p>
<p><strong>7.</strong> Open your PowerShell Profile with notepad with the command below:</p>
<blockquote>
<pre>
notepad $profile
</pre>
</blockquote>
<p><strong>8.</strong> Assuming that you are running Server 2008 and this is the first time creating a PowerShell profile, Notepad should display an error that the file was not found.</p>
<p>Click Ok to close the error and return to PowerShell to rectify the problem.</p>
<p><strong>9.</strong> Try using the command below to create the profile file:</p>
<blockquote>
<pre>
create-item $profile –type “file”
</pre>
</blockquote>
<p><strong>10.</strong> The previous command attempts to create the profile file under your ‘Documuents\Windows PowerShell’ directory, but with no Windows PowerShell directory, no file was created</p>
<p><strong>11.</strong> Use some PowerShell power to create the directory then the profile file by entering the commands below:</p>
<blockquote><pre>
new-item $profile.SubString(0, $profile.LastIndexOfAny(“\\”))
create-item $profile –type “file”
</pre>
</blockquote>
<blockquote><p>
<strong>Note:</strong> If you have any experience with the .NET framework the first command of this step should look familiar. It utilizes the methods of the string object to parse the profile path out of the profile variable.
</p></blockquote>
<p><strong>12.</strong> Open the newly created file by entering <code>notepad $profile</code> again</p>
<p><strong>13.</strong> Enter the property changes as you would in PowerShell into the profile file. Below is an example of the contents of a profile file with the same setting examples in these steps:</p>
<blockquote>
<pre>
$psui = (get-host).UI.RawUI
$psbs = $psui.BufferSize
$psui.WindowTitle = “PowerShell PowerStation”
$psui.BackGroundColor = “Blue”
$psui.ForeGroundColor = “Yellow”
$psbs.Height = 3000
$psbs.Width = 120
cls
</pre>
</blockquote>
<p><strong>14.</strong> Click File | Save to save the changes to the profile</p>
<p>If script execution is enabled, when you launch PowerShell it will automatically start with the configuration set in the profile file. If not enabled, proceed to the next section for information on enabling it.</p>
<p>This example only covers customizing the PowerShell console window. Keep in mind that any variables or functions you define in the profile file will be automatically available for use when you launch PowerShell.</p>
<p>This is it for today! Next week we&#8217;ll go into PowerShell scripting &#8212; so don&#8217;t miss the last article of taking command of Server 2008 with Windows PowerShell. See you next week!</p>


<h3>Related posts:<ul><li><a href='http://windowsserver.trainsignal.com/windows-server-2008-powershell-2' rel='bookmark' title='Permanent Link: Take Command of Server 2008 with Windows PowerShell &#8211; Part 2'>Take Command of Server 2008 with Windows PowerShell &#8211; Part 2</a></li>
<li><a href='http://windowsserver.trainsignal.com/windows-server-2008-powershell' rel='bookmark' title='Permanent Link: Take Command of Server 2008 with Windows PowerShell &#8211; Part 1'>Take Command of Server 2008 with Windows PowerShell &#8211; Part 1</a></li>
<li><a href='http://windowsserver.trainsignal.com/windows-server-2008-powershell-4' rel='bookmark' title='Permanent Link: Take Command of Server 2008 with Windows PowerShell &#8211; Part 4'>Take Command of Server 2008 with Windows PowerShell &#8211; Part 4</a></li>
</ul></h3>]]></content:encoded>
			<wfw:commentRss>http://windowsserver.trainsignal.com/windows-server-2008-powershell-3/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Take Command of Server 2008 with Windows PowerShell &#8211; Part 2</title>
		<link>http://windowsserver.trainsignal.com/windows-server-2008-powershell-2</link>
		<comments>http://windowsserver.trainsignal.com/windows-server-2008-powershell-2#comments</comments>
		<pubDate>Wed, 06 Feb 2008 16:30:15 +0000</pubDate>
		<dc:creator>Jason Ensinger</dc:creator>
				<category><![CDATA[Server 2008]]></category>
		<category><![CDATA[cmdlets]]></category>
		<category><![CDATA[Command Shell]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://www.trainsignaltraining.com/windows-server-2008-powershell-2/2008-02-06/</guid>
		<description><![CDATA[
Welcome back! Today we&#8217;re learning about PowerShell Cmdlets and PowerShell Providers.
If you missed the first part of this short series, make sure to take a look at it when you get a chance.
Take Command of Server 2008 with Windows PowerShell &#8211; Part 1 will provide you with a good introduction to PowerShell and show you [...]

<h3>Related posts:<ul><li><a href='http://windowsserver.trainsignal.com/windows-server-2008-powershell' rel='bookmark' title='Permanent Link: Take Command of Server 2008 with Windows PowerShell &#8211; Part 1'>Take Command of Server 2008 with Windows PowerShell &#8211; Part 1</a></li>
<li><a href='http://windowsserver.trainsignal.com/windows-server-2008-powershell-4' rel='bookmark' title='Permanent Link: Take Command of Server 2008 with Windows PowerShell &#8211; Part 4'>Take Command of Server 2008 with Windows PowerShell &#8211; Part 4</a></li>
<li><a href='http://windowsserver.trainsignal.com/windows-server-2008-powershell-3' rel='bookmark' title='Permanent Link: Take Command of Server 2008 with Windows PowerShell &#8211; Part 3'>Take Command of Server 2008 with Windows PowerShell &#8211; Part 3</a></li>
</ul></h3>]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.trainsignaltraining.com/wpnew/wp-content/uploads/2008/01/PowerShell2.jpg" alt="Windows Power Shell" title="Windows Power Shell" align="right" width="251" height="200" border="0" /></p>
<p>Welcome back! Today we&#8217;re learning about PowerShell Cmdlets and PowerShell Providers.</p>
<p>If you missed the first part of this short series, make sure to take a look at it when you get a chance.</p>
<p><a href="http://windowsserver.trainsignal.com/windows-server-2008-powershell"><strong>Take Command of Server 2008 with Windows PowerShell &#8211; Part 1</strong></a> will provide you with a good introduction to PowerShell and show you the steps to installing and accessing PowerShell on your Server 2008.</p>
<p>Now let&#8217;s get started with Cmdlets, the essence of Windows PowerShell.</p>
<h3>Understanding PowerShell Cmdlets</h3>
<p>Taking advantage of the power of PowerShell is done with the use of cmdlets. The cmdlets are powered by a set of .NET objects and methods developed with server and network administrative purposes in mind.</p>
<p><span id="more-414"></span></p>
<p>An example of a cmdlet is <code>Get-ChildItem</code>, which is used for listing the contents of an object. That’s right, object.</p>
<p>Any output created within PowerShell is output in the form of an object as opposed to text. An object is an item that can contain multiple properties and/or methods, which can return more objects.</p>
<p>If no action is performed on an object, PowerShell outputs the object details in text form. Actions can be performed on an object returned by a cmdlet by pipelining another command with the pipe character between commands.</p>
<p>The command below lists the contents of the current object (directory) sorted by name in descending order.</p>
<blockquote><pre>
get-childitem | sort-object “Name” –descending
</pre>
</blockquote>
<p>In the above example, the Sort-Object cmdlet is used on the return object of the <code>Get-ChildItem</code> cmdlet to sort by the Name property. Tacked onto the end of the command are the property and descending parameters.</p>
<p>The actions performed by cmdlets are determined by the parameters supplied to the cmdlet. Alternatively you could have supplied the –property parameter flag before “Name”, but because that is the cmdlet’s default parameter, that is not necessary.</p>
<p>Aside from the cmdlet specific parameters, you can also use common parameters with cmdlets to be handled by the PowerShell engine itself.</p>
<p>Not all cmdlets support all the common parameters; most of them usually work though. The common PowerShell parameters are defined below:</p>
<ul>
<li><code>-confirm</code> – Prompts the user for confirmation before executing a command.</li>
<p></p>
<li><code>-debug</code> – Tells the cmdlet to provide debugging information.</li>
<p></p>
<li><code>-ErrorAction</code> – Allows the cmdlet to; continue, stop, silently continue or inquire when an error occurs.</li>
<p></p>
<li><code>-ErrorVariable</code> – Tells the cmdlet to assign error information to the variable specified.</li>
<p></p>
<li><code>-OutBuffer</code> – Tells the cmdlet to hold a certain number of objects before calling a pipelined cmdlet.</li>
<p></p>
<li><code>-OutVariable</code> – Tells the cmdlet to assign output to the variable specified.</li>
<p></p>
<li><code>-verbose</code> – Tells the cmdlet to provide more detail.</li>
<p></p>
<li><code>-whatif</code> – Tells the result of executing the command without executing it.</li>
</ul>
<p>If you have been working along, you probably noticed that the output from the <code>Get-ChildItem</code> cmdlet looks a lot like what you would expect to see by entering dir. This is no coincidence.</p>
<p>When you enter dir you are actually entering the alias assigned to the <code>Get-ChildItem</code> cmdlet. Cmdlets come with pre-assigned aliases and can also have custom defined aliases.</p>
<p>Cmdlet aliases can be listed with the <code>Get-Alias</code> and set with the <code>Set-Alias</code> cmdlets.</p>
<p>Should you ever have the need to find out more information on a cmdlet you can use the <code>Get-Help</code> cmdlet. The <code>Get-Help</code> cmdlet itself has parameters such as <code>–detailed</code> and <code>–full</code> for determining the amount of help shown.</p>
<p>If you ever have trouble remembering the name of a cmdlet you can use the <code>Get-Command</code> cmdlet. Entering <code>Get-Command</code> by itself lists all the PowerShell cmdlets. You can also supply part of a cmdlet name to narrow down the results like in the example below:</p>
<blockquote><pre>
get-command get-
</pre>
</blockquote>
<p>Executing the above command lists all the cmdlets that begin with ‘get-‘. The <code>Get-Help</code> and <code>Get-Command</code> cmdlets should prove very useful for helping you to get familiar with the capabilities and usage of PowerShell.</p>
<h3>Understanding PowerShell Providers</h3>
<p>By default, when PowerShell is launched, you will start with your profile folder as your working directory. Access to this directory is available to you courtesy of the FileSystem provider.</p>
<p>PowerShell providers take the form of logical drives that provide access to data stored within the drives in a fashion that can be navigated and manipulated using the PowerShell cmdlets.</p>
<p>PowerShell comes packaged with seven default providers. You can list the available providers and their respective drives with the <code>Get-PSProvider</code> cmdlet. Additional providers can be installed with the <code>New-PSDrive</code> cmdlet.</p>
<p>The default PowerShell providers are explained below:</p>
<ul>
<li><strong>Alias</strong> – Provides access to the aliases assigned to cmdlets.</li>
<p></p>
<li><strong>Certificate</strong> – Provides the ability to sign and work with scripts.</li>
<p></p>
<li><strong>Environment</strong> – Provides access to the Windows Environment variables that hold information on configuration and special folders.</li>
<p></p>
<li><strong>FileSystem</strong> – Provides access to the files and folders available on your local drives.</li>
<p></p>
<li><strong>Function</strong> – Provides access to the functions defined in PowerShell.</li>
<p></p>
<li><strong>Registry</strong> – Provides access to the Windows registry.</li>
<p></p>
<li><strong>Variable</strong> – Provides access to the variables assigned in PowerShell.</li>
</ul>
<p>You can gain access to the different PowerShell providers by using the <code>Set-Location</code> cmdlet. The command below will change the working directory to the Variable provider.</p>
<blockquote><pre>
set-location variable:
</pre>
</blockquote>
<p>From the Variable provider you can list all the variables assigned in the console and their respective values with the <code>Get-ChildItem</code> cmdlet. You can also create new variables using the <code>New-Item</code> cmdlet or remove them with the <code>Remove-Item</code> cmdlet amongst other things.</p>
<p>It&#8217;s important to note that the Variable provider is not the only place you can work with variables. Variables can be assigned or used anywhere you go with PowerShell.</p>
<p>Variables are identified in the PowerShell console with the dollar sign. Executing the command below will assign a value to a variable.</p>
<blockquote><pre>
$variable = “I’m a variable”
</pre>
</blockquote>
<p>To display the newly assigned variable, execute the command below.</p>
<blockquote><pre>
$variable
</pre>
</blockquote>
<p>Providers give great potential for expanding the capabilities of PowerShell. They provide access for working with many resources on the server.</p>
<p>The PowerShell provider system has removed the restriction of working solely with the server’s file system within the command shell environment.</p>
<p>We&#8217;re done for today, but don&#8217;t forget to come back next week for more on taking command of Server 2008 with Windows PowerShell!</p>


<h3>Related posts:<ul><li><a href='http://windowsserver.trainsignal.com/windows-server-2008-powershell' rel='bookmark' title='Permanent Link: Take Command of Server 2008 with Windows PowerShell &#8211; Part 1'>Take Command of Server 2008 with Windows PowerShell &#8211; Part 1</a></li>
<li><a href='http://windowsserver.trainsignal.com/windows-server-2008-powershell-4' rel='bookmark' title='Permanent Link: Take Command of Server 2008 with Windows PowerShell &#8211; Part 4'>Take Command of Server 2008 with Windows PowerShell &#8211; Part 4</a></li>
<li><a href='http://windowsserver.trainsignal.com/windows-server-2008-powershell-3' rel='bookmark' title='Permanent Link: Take Command of Server 2008 with Windows PowerShell &#8211; Part 3'>Take Command of Server 2008 with Windows PowerShell &#8211; Part 3</a></li>
</ul></h3>]]></content:encoded>
			<wfw:commentRss>http://windowsserver.trainsignal.com/windows-server-2008-powershell-2/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Take Command of Server 2008 with Windows PowerShell &#8211; Part 1</title>
		<link>http://windowsserver.trainsignal.com/windows-server-2008-powershell</link>
		<comments>http://windowsserver.trainsignal.com/windows-server-2008-powershell#comments</comments>
		<pubDate>Wed, 30 Jan 2008 18:30:31 +0000</pubDate>
		<dc:creator>Jason Ensinger</dc:creator>
				<category><![CDATA[Server 2008]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[cmdlets]]></category>
		<category><![CDATA[Command Shell]]></category>
		<category><![CDATA[FileSystem]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[VB Script]]></category>

		<guid isPermaLink="false">http://www.trainsignaltraining.com/windows-server-2008-powershell/2008-01-30/</guid>
		<description><![CDATA[Since the earliest versions of Microsoft Windows, the command shell has existed in some way, shape, or form.
The command shell evolved from direct entry into Windows underlying DOS environment to an emulated DOS Environment in later Windows versions.
All the while the command shell has made strides to maintain backward compatibility with the original DOS environment, [...]

<h3>Related posts:<ul><li><a href='http://windowsserver.trainsignal.com/windows-server-2008-powershell-2' rel='bookmark' title='Permanent Link: Take Command of Server 2008 with Windows PowerShell &#8211; Part 2'>Take Command of Server 2008 with Windows PowerShell &#8211; Part 2</a></li>
<li><a href='http://windowsserver.trainsignal.com/windows-server-2008-powershell-3' rel='bookmark' title='Permanent Link: Take Command of Server 2008 with Windows PowerShell &#8211; Part 3'>Take Command of Server 2008 with Windows PowerShell &#8211; Part 3</a></li>
<li><a href='http://windowsserver.trainsignal.com/windows-server-2008-powershell-4' rel='bookmark' title='Permanent Link: Take Command of Server 2008 with Windows PowerShell &#8211; Part 4'>Take Command of Server 2008 with Windows PowerShell &#8211; Part 4</a></li>
</ul></h3>]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.trainsignaltraining.com/wpnew/wp-content/uploads/2008/01/PowerShell2.jpg" alt="Windows PowerShell" title="Windows PowerShell" align="right" width="251" height="200" border="0" />Since the earliest versions of Microsoft Windows, the command shell has existed in some way, shape, or form.</p>
<p>The command shell evolved from direct entry into Windows underlying DOS environment to an emulated DOS Environment in later Windows versions.</p>
<p>All the while the command shell has made strides to maintain backward compatibility with the original DOS environment, however, little has been done to expand upon the capabilities of the command shell.</p>
<p>Utilizing the power of the .NET Framework, Microsoft has released a brand new command shell environment aptly titled <strong>Windows PowerShell</strong>.</p>
<h3>Introducing: Windows PowerShell</h3>
<p>Like its predecessors, <strong>Windows PowerShell</strong> supports all the previous command shell commands such as &#8220;cd&#8221; to change directories, and &#8220;dir&#8221; to list directory contents, and converting your old batch files to PowerShell scripts is virtually effortless.</p>
<p><span id="more-410"></span></p>
<p>But don’t be fooled by the fact that PowerShell can execute old commands and batch files. PowerShell is run by a brand new command set consisting of some 120 cmdlets.</p>
<p>Cmdlets make themselves useful within each of the PowerShell providers. Providers are objects that store their data in a structure navigable like the Windows File and directory system.</p>
<p>In fact, the default PowerShell provider is the FileSystem provider, which gives access to the files and folders stored on the system drives.</p>
<p>PowerShell’s automation and time saving capabilities become apparent when you take advantage of three key features.</p>
<ul>
<li>Pipelining command objects together</li>
<li>Multiple commands separated by semicolons on a single line</li>
<li>Powerful and flexible scripting engine</li>
</ul>
<p>With all that, PowerShell not only acts as a replacement to the standard Windows Command Prompt, in many ways its usefulness as an administrative scripting engine exceeds that of VB Script. PowerShell scripting can accomplish virtually everything VB Script can and do it with greater efficiency in several areas.</p>
<h3>Installing Windows PowerShell</h3>
<p>Now that you have heard of this new tool, you are probably wondering how to get your hands on all that power?</p>
<p>Like most of Windows Server 2008’s useful features, Windows PowerShell is not installed as a default Windows Component. This is mostly because Windows PowerShell is dependent on .NET Framework 2.0 or higher being installed.</p>
<p>Assuming your installation of Server 2008 meets these requirements, PowerShell can be installed by following the steps below:</p>
<ol>
<li>Open the Server Manager from Start | Control Panel | Administrative Tools | Server Manager</li>
<p></p>
<li>From the Server Manager Click Features then click Add Features</li>
<p></p>
<li>Check the box labeled Windows PowerShell and click the Next button</li>
<p></p>
<li>Click the Install button to confirm installation and wait</li>
<p></p>
<li>When the installation is complete, click the Close button to exit the Add Features Wizard</li>
</ol>
<h3>Accessing Windows PowerShell</h3>
<p>With PowerShell now pleasantly residing on your server, all that is necessary to bring the power to your fingertips is launching it.</p>
<p>Like many Windows features, PowerShell can be accessed more ways than one. Below are the basic methods for accessing PowerShell.</p>
<ul>
<li>Start | Run | PowerShell.exe</li>
<li>Start | All Programs | Windows PowerShell 1.0 | Windows PowerShell</li>
<li>From the standard Command Prompt by entering PowerShell.exe</li>
</ul>
<p>If you prefer, you could also copy the PowerShell shortcut from the start menu to the desktop or quick launch tool bar for easier access.</p>
<h3>But Wait! There&#8217;s More &#8230;</h3>
<p>That&#8217;s all for today, but don&#8217;t worry, in the next few weeks, you will have the opportunity to get fully acquainted with <strong>Windows PowerShell</strong> through a series of articles, this one being the first.</p>
<p>The main goal of this series is to show you the capabilities and proper usage of Windows PowerShell. So that after reading all the articles you will be familiar with the following:</p>
<ul>
<li>Installing and Accessing Windows PowerShell on Windows Server 2008.</li>
<p></p>
<li>Launching the PowerShell command console.</li>
<p></p>
<li>Executing cmdlets and working with the objects returned.</li>
<p></p>
<li>Using the different PowerShell providers to work with server resources inaccessible from the FileSystem provider.</li>
<p></p>
<li>Using variables to store and reuse objects in PowerShell.</li>
<p></p>
<li>Customizing the user interface of PowerShell with the PowerShell profile.</li>
<p></p>
<li>Taking advantage of the script engine to automate the performance of Administrative tasks on the Server.</li>
</ul>


<h3>Related posts:<ul><li><a href='http://windowsserver.trainsignal.com/windows-server-2008-powershell-2' rel='bookmark' title='Permanent Link: Take Command of Server 2008 with Windows PowerShell &#8211; Part 2'>Take Command of Server 2008 with Windows PowerShell &#8211; Part 2</a></li>
<li><a href='http://windowsserver.trainsignal.com/windows-server-2008-powershell-3' rel='bookmark' title='Permanent Link: Take Command of Server 2008 with Windows PowerShell &#8211; Part 3'>Take Command of Server 2008 with Windows PowerShell &#8211; Part 3</a></li>
<li><a href='http://windowsserver.trainsignal.com/windows-server-2008-powershell-4' rel='bookmark' title='Permanent Link: Take Command of Server 2008 with Windows PowerShell &#8211; Part 4'>Take Command of Server 2008 with Windows PowerShell &#8211; Part 4</a></li>
</ul></h3>]]></content:encoded>
			<wfw:commentRss>http://windowsserver.trainsignal.com/windows-server-2008-powershell/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
