<?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; cmdlets</title>
	<atom:link href="http://windowsserver.trainsignal.com/tag/cmdlets/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>Wed, 17 Mar 2010 14:00:18 +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>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>2</slash:comments>
		</item>
	</channel>
</rss>
