Windows PowerShell 3.0

Windows PowerShell 3.0Windows PowerShell 3.0

Version 3 is a major upgrade of PowerShell; it has intellisense features to make newbies sure-footed as they walk through their commands.  PowerShell 3.0 also has new structures such as Workflow to make the experts more productive.

PowerShell 3.0 New Features

 ♦

What's New In PowerShell 3.0

Microsoft has incremented this programming language by a whole integer from version 2.0 to 3.0, thus you would expect significant changes, and you won't be disappointed.  We had tab-completion in version 2, but now we have a lovely intellisense Auto-complete to help you type the cmdlets quickly and accurately.

As for the cmdlets and functions, there are hundreds of new tools.  Here is my review of the all the new features to help beginners, and to facilitate old hands in working that bit slicker.  What's new in PowerShell 3.0 »

Show-CommandNew Cmdlet in PowerShell 3.0 Show-Command

If you want to test the parameters of an unfamiliar PowerShell cmdlet, then Show-Command is ideal for experimenting.  Think of it as taking the GUI one stage further.

# PowerShell 3.0 Show-Command
Show-Command Get-ChildItem

Observe how it illustrates -recurse and -force to help those who are not familiar with these parameters.  See more on Show-Command »

PowerShell 3.0's New 'Where' Statement

The new simplified Where statement is one of the most controversial features of PowerShell 3.0.  It reminds me of learning to ride a bike with those stabilizing wheels, they are OK for a while, but sooner or later you have to take them off the bike.  The new simplified Where is great for the basics, but not good for more complex syntax involving -Not or -And.

Traditional PowerShell 'Where' construction

# PowerShell where filter to list the exe files C:\program Files
GCI "C:\Program Files" -Recurse | where {$_.extension -eq ".exe"}

New streamlined 'Where' construction
See how the {curly brackets} and $_.placeholder have been stripped out.

# PowerShell 3.0 Plain Where
Get-ChildItem | Where extension -eq 'exe'

See more on PowerShell 3.0 Where statement »

Guy Recommends:  A Free Trial of the Network Performance Monitor (NPM)Review of Orion NPM v11.5 v11.5

SolarWinds' Network Performance Monitor will help you discover what's happening on your network.  This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.

What I like best is the way NPM suggests solutions to network problems.  Its also has the ability to monitor the health of individual VMware virtual machines.  If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.

Download a free trial of Solarwinds' Network Performance Monitor

PowerShell 3.0 New Comparators -NotIn and -In

I love PowerShell's comparators such as -Match and -Like, now in PowerShell version 3 we have two additional comparison operators: -In and -NotIn.  So far I have found -In (or its negative -NotIn) are most suited to numeric comparisons, where -Match does not make arithmetic sense.

# PowerShell -In
'75' -In '1..7000'
# True

-Match or -Like would not make sense here.  See more on PowerShell 3.0 -In »

PowerShell 3.0 WorkflowPowerShell 3.0 Workflow

Workflow has been around since the birth of scripting.  At last in PowerShell 3.0 Microsoft has introduced a structured method for performing multiple tasks in a particular sequence.  As well putting the logic of those lovely workflow charts into action, PowerShell's Workflow are great at resuming if they are interrupted by a flaky network connection.

Although scripting workflow is for experts rather than beginners, the hardest part of coding workflow is not the PowerShell commands, but ensuring that your logic produces the desired results.  See more on PowerShell 3.0 Workflow »

PowerShell 3.0 Update-Help

Occasionally there are errors in built-in help files.  The concept update help is to amend typos and to clarify the help that ships with PowerShell 3.0.  That said, employing Update-Help is tricky especially where you are not using the default English version.   See more on PowerShell 3.0 Update-Help »

Engineer's Toolset v10Guy Recommends: SolarWinds Engineer's Toolset v10

This Engineer's Toolset v10 provides a comprehensive console of 50 utilities for troubleshooting computer problems.  Guy says it helps me monitor what's occurring on the network, and each tool teaches me more about how the underlying system operates.

There are so many good gadgets; it's like having free rein of a sweetshop.  Thankfully the utilities are displayed logically: monitoring, network discovery, diagnostic, and Cisco tools.  Try the SolarWinds Engineer's Toolset now!

Download your fully functional trial copy of the Engineer's Toolset v10

PowerShell 3.0 Introduces Ordered Hash Tables

Here is an example of the developers listening to requests, while coders use hashtables extensively, there was a growing frustration in PowerShell 2 that you could not order the values.  All of that is the past with Hash Tables in PowerShell 3.0.

#Hash Table Problem
$GuyHash = @{Wales=1; England=2; Scotland=3; Ireland =4}
$GuyHash

Problem: Sequence 3,1,4,2

Name Value
--------  ----
Scotland  3
Wales      1
Ireland    4
England   2

Solution: Precede the hashtable with [Ordered]

#Ordered Hash Table Solution
$GuyHash = [Ordered]@{Wales=1; England=2; Scotland=3; Ireland =4}
$GuyHash

Name Value
--------  ----
Wales      1
England   2
Scotland  3
Ireland    4

See more on PowerShell 3.0 hashtables »

How to Control PowerShell's Default Parameters

The reason for creating defaults for parameters is to save typing.  The easiest way to control these values is to combine $PSDefaultParameterValues with an array.

# Three example of setting parameter defaults.
$PSDefaultParameterValues=@{
"Restart-Service:name" ="Spooler" ;
"Get-ChildItem:path " ="C:\Windows\System32" ;
"Get-Date:uformat" = "%A, %d:%m:%Y" ;
}

This is just a taster of how you can pre-determine what happens when you type a command such as Get-Eventlog. See more on PowerShell 3.0's default parameters.

Guy Recommends: Free WMI Monitor for PowerShellSolarwinds Free WMI Monitor for PowerShell

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft's operating systems.  Fortunately, SolarWinds have created a Free WMI Monitor so that you can discover these gems of performance information, and thus improve your PowerShell scripts.

Take the guess work out of which WMI counters to use when scripting the operating system, Active Directory, or Exchange Server. Give this WMI monitor a try - it's free.

Download your free copy of WMI Monitor

New Networking Cmdlets

PowerShell 3.0 provides a family of cmdlets to deal with the network adapter.  Here is an example where we get all the network adapters and then Disable a named example called 'Wi-Fi'.

Get-NetAdapter | Where {$_.name -Match 'Wi-Fi'} |  Disable-NetAdapter
Get-NetAdapter

See more about PowerShell's Disable-NetAdapter

Getting Started with PowerShell v 3.0PowerShell 3.0

Let us assume that you have just launched Windows 8 with its Metro UI.

  • Just type the letter 'p'.  You will see a list of the programs and Apps beginning with the 'p'.
  • My advice is to select the ISE version rather than the plain command-line Windows PowerShell.
  • Because I use PowerShell regularly I like to Pin the application to a tile on in the Metro UI.
  • Next: What's New in PowerShell 3.0 ISE »

PowerShell 3.0 JSON

If you need to convert JavaScript syntax to PowerShell then we now have ConvertTo-JSON and ConvertFrom-JSON cmdlets to deal with the tricky syntax interchange.

PowerShell 3.0 Update-Help

The improvements in Update-Help remind me of the old maxim, 'Never use software before it reaches version 3.  In PowerShell 1.0 there was no possibility of updating the help files.  PowerShell 2.0 introduced the -online parameter, but it's only in PowerShell 3.0 that we have a built-in cmdlet to refresh the help files when Microsoft discover errors in PowerShell help documents.  See more on PowerShell 3.0 Update-Help.

Summary of PowerShell 3.0

Windows 8 was the catalyst for the release of PowerShell version 3.0.  Enjoy the improvements not only in more cmdlets, but also in cleverness of the program.  This new version of PowerShell helps Microsoft achieve its goal to give users the capability to develop their own tools.

If you like this page then please share it with your friends

 


See more Windows PowerShell sections

PowerShell Home   • Introduction  • Dreams   • 3 Key Commands   • Free Permissions Analyzer

PowerShell Real-life Examples   • PowerShell Techniques   • PowerShell Syntax   • Contact

PowerShell ISE  • PowerShell 2.0   • PowerShell v 3.0   • PowerShell v 4.0   • PowerShell v 4.0

Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.

 

 *


Custom Search

Site Home

Guy Recommends: WMI Monitor for PowershellSolarwinds WMI Monitor

Windows Management Instrumentation (WMI) is most useful for PowerShell scripting.

SolarWinds have produced this Free WMI Monitor to take the guess work out of which WMI counters to use for applications like Microsoft Active Directory, SQL or Exchange Server.

Download your free copy of WMI Monitor

Author: Guy Thomas Copyright © 1999-2016 Computer Performance LTD All rights reserved.

Please report a broken link, or an error to: