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.
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-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.
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'
Here is an utility where you can review firewall settings such as
access control lists (ACL), or troubleshoot problems with network
address translation (NAT).
Other reasons to download this SolarWinds Firewall Browser include
managing requests to change your firewall settings, testing firewall
rules before you go live, and querying settings with the browser's
powerful search options.
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.
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 »
Guy 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!
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.
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" ; }
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.
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
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
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.
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.