Top 5 Things to Love about PowerShell

Windows PowerShell will be a great asset to all administrators, regardless of your scripting ability. Here are my top 5 reasons I am going to love working with PowerShell.

5.  PowerShell is a command console with color! By using the -foregroundcolor and -backgroundcolor of the Write-Host cmdlet, I can add color coding to provide additional feedback.

# ShowServices.ps1
# stopped services will display in RED
# running services will display in GREEN
$strComputer=”.”
$colItems=get-wmiobject -class “Win32_Service” -namespace “root\CIMV2” `
-computername $strComputer | sort “Caption”

foreach ($objItem in $colItems) {
    if ($objItem.State -eq “Running”) {
    Write-Host $objItem.Caption “(“$objItem.Name”)”  -foregroundcolor “green” }
    else {Write-Host $objItem.Caption “(“$objItem.Name”)” -foregroundcolor “red” }
}

will produce output like this
PowerShell Colorized Output
4.  PowerShell is self-explanatory. Want to know what a cmdlet does? Ask! Usually you can just type something like:
help cmdlet
If you want more information you can type: help cmdlet -detailed or type help cmdlet -full for everything.

3.  PowerShell is secure by nature and design. By default it won’t execute any scripts. PowerShell even prefers that all its scripts be signed.  You have these choices for execution policy:
 — Restricted: Does not load configuration files or run scripts. “Restricted” is the default.
 — AllSigned: Requires that all scripts and configuration files be signed by a trusted publisher, including scripts that you write on the local computer.
 — RemoteSigned: Requires that all scripts and configuration files downloaded from the Internet be signed by a trusted publisher.
 — Unrestricted: Loads all configuration files and runs all scripts. If you run an unsigned script that was downloaded from the Internet, you are prompted for permission before it runs.

Use Get-ExecutionPolicy to find out your current settings and Set-ExecutionPolicy to set it.

2.  PowerShell is first and foremost a management shell. It is designed to get things done. As a bonus it can be :scripted” either interactively or by putting all the necessary expressions in a .ps1 file. If you’ve worked with the traditional CMD shell this is really no different. You can run commands from a C: prompt, or put them in a batch file. The same is true in PowerShell.  Think of the .ps1 file as “batch” file for PowerShell.

And the number one reason we’re all going to love PowerShell…

1.  It is object oriented. Whereas the CMD shell was all text based, PowerShell is based on .NET objects. It may look like you are working with text, but you can create, manipulate and make PowerShell objects obey your every whim (with a little practice of course).  Once you understand how you can take one object and pass it to another you’ll really under stand the power in this new shell.