Guy recommends :
Free SolarWinds
VM Console

Solarwinds VM Console Free Download

Find out which of your VMs are a waste of space and which VMs need more resources.



What's New in PowerShell 3.0

New Features in Windows PowerShell 3.0What's New in PowerShell 3.0

The advent of Windows 8 (client) and Windows Server 8 see the introduction of a new version of PowerShell.  My aim on this page is to get you started, and to explain these new features.

 ♦

Download PowerShell v3.0 CTP

As an alternative to installing Windows 8, if you have Windows 7 with SP1, or Windows Server 2008 R2 SP1, then you can download the Community Technology Preview version, see here for PowerShell 3.0 CTP.

Launching PowerShell v 3.0PowerShell 3.0

This is how to get started from the Metro user interface in Windows 8.

  • From anywhere in the Metro UI, press the 'p' key.  You should see a list of the programs and Apps beginning with the letter 'p'.
  • At this point you could 'Pin' the 'Windows PowerShell ISE'.  Simply right-click the icon and selecting 'Pin' at the bottom right of the screen.
  • Incidentally, I prefer the GUI (ISE) version to the plain command line Windows PowerShell.
  • I like to drag the PowerShell ISE tile to the left of my screen because it's one of the most important Windows 8 Tiles that use.
  • To download Windows 8 with PowerShell 3.0 see here.

Check PowerShell's Version

# PowerShell Version
$PSVersionTable

Once your PowerShell ISE arrives it's worth double-checking its version: type: $PSVersionTable

Result
Name        Value
-------       -------
PSVersion  3.0  [Assuming you have Windows 8]

Note 1: Alteratively you could try: $Host, or even Get-Host.

What's New In PowerShell v 3.0?Microsoft Windows 8 PowerShell

The Auto-complete feature saves typing time, and reduces my typos.  As you begin to type a cmdlet so you see a pick-list of likely nouns to append to your verb.

See screenshot to the right, once you have typed the verb (Get) and the first letter of the noun (-P) then the list of available cmdlet appears.  In this example if you pressed 'Enter' then PowerShell would complete the typing (Get-Partition).  To be precise, the list usually appears once you have typed the verb and the hyphen.

Microsoft also provide a nifty way to group the cmdlets by module, see under 'Commands' in the screenshot below taken from the PowerShell 3.0 ISE:

Windows PowerShell v3

Guy Recommends: WMI Monitor and It's Free!Solarwinds Free WMI Monitor

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft 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.

Download your free copy of WMI Monitor

See Dozens of New PowerShell 3.0 CmdletsMicrosoft Windows 8 PowerShell

Whereas PowerShell v 2.0 brought remoting, PowerShell v 3.0 brings hundreds of new cmdlets.

# PowerShell 3.0 Cmdlet count
$Pv3 = Get-Command *
$Pv3.count

You could shorten to: (Get-Command *).count

List Just Cmdlets and Functions

You could modify the script to avoid the duplication of cmdlets' aliases.

Observe how this script sorts the 'CommandType' in descending order, and the 'Name' in ascending order.

Clear-Host
$Pv3 = Get-Command | `
Where-Object {$_.CommandType -eq 'Function' -or $_.CommandType -eq 'Cmdlet'}
$Pv3 | Sort-Object -property `
@{Expression="CommandType";Descending=$true}, `
@{Expression="Name";Descending=$false} | FT Name, CommandType -auto
$Pv3.count

Note 2: The biggest expansion area in PowerShell 3.0's is of functions.  I draw your attention to this because many of these 'Functions' look for all the world like cmdlets.  In particularly, I am thinking of the 'Net' family with nouns such as: NetIPAddress, NetIPAdapter and NetIPInterface.

To see what I mean try this:

Clear-Host
$Pv3f = Get-Command | `
Where-object {$_.CommandType -eq 'Function'}
$Pv3f | Sort-Object -property `
@{Expression="CommandType";Descending=$true}, `
@{Expression="Name";Descending=$false} | FT CommandType, Name -auto
$Pv3f.count

Note 3: I got 513 functions in PowerShell 3.0, but only 38 in PowerShell 2.0.

Show-Command

There is another useful new cmdlet called Show-Command; the idea is for beginners to research more about the syntax of a cmdlet, I have chosen Get-Eventlog, but you could experiment with any PowerShell verb-noun pair.

# PowerShell 3.0 Favourite New Command
Show-Command Get-Eventlog

PowerShell Show-Command Get-Event

Note 4: See more about Show-Command.

PowerShell 3.0 Intellisense

When you make mistakes, PowerShell 3.0 underlines the error in red, furthermore, if you hover on the wavy line Intellisense supplies suggestions to correct the error.  For example:

# PowerShell 3.0 Intellisense
Get-Service | Where {$_.status -eq running }

Problem:  running should be encased in single speech marks.  It should be:
Get-Service | Where {$_.status -eq 'running' }

Solution: Click on the red line and PowerShell suggests a solution.

PowerShell Show-Command Get-Event

Guy Recommends:  SolarWinds' Free Bulk Import ToolFree Download of Solarwinds  Bulk Import Tool

Import users from a spreadsheet.  Just provide a list of the users with their fields in the top row, and save as .csv file.  Then launch this FREE utility and match your fields with AD's attributes, click to import the users.  Optionally, you can provide the name of the OU where the new accounts will be born.

There are also two bonus tools in this free download, and all 3 have been approved by Microsoft:

  1. Bulk-import new users into Active Directory.
  2. Seek and zap unwanted user accounts.
  3. Find inactive computers.

Download your FREE bulk import tool.

The 'Where' Statement is Simplified in PowerShell 3.0

The best way to see what's changed with WHERE is through two examples:

# PowerShell 2.0 Where {}
Get-Service | Where {$_.status -eq 'running' }

Note 5: The above example works in version PowerShell 2.0 and 3.0
Note 6: Below is a simplification, but it works only in PowerShell v 3.0

# PowerShell 3.0 Plain Where
Get-Service | Where status -eq 'running'

Note 7: Observe how the {curly brackets}, the placeholder ($_.) and the 'speech marks' have been stripped out, making this Where-Object command much easier for everyone to read, and for newbies to type.  Incidentally, some old-hands cannot believe this simplified syntax really will work!  But it does!!  See more on PowerShell 3.0 Where statement.

More New Features in PowerShell 3.0PowerShell 3.0 Passthru

Out-GridView now has the -passthru parameter.  The benefit occurs if you select rows with the mouse and then refresh the command, the output reflects just that data, in effect selecting enables filtering.  See screenshot to the right where I have selected just 5 rows, if we clicked on the 'OK' button -passthru would filter just: dlhost, LogonUI etc...

See more on -PassThru in PowerShell 3.0

Update-Help  Anyone who writes articles knows there are inevitably mistakes, and help files are no exception, what's new in version 3.0 is an Update-Help cmdlet.  This cures those small errors, or annoying typos, in the built-in documentation.  Naturally, for this to be effective someone at Microsoft must update the master help file on the internet!

Change The Default Parameters  It's possible to adjust the default value for a cmdlet's parameter.  For example, suppose you wanted Out-File to write in ASCII, then try this:
$PSDefaultParameterValues.('Out-File:encoding = ascii')

Where Encoding is the parameter (stripped of its hyphen), and ascii is your preferred format.  Pay close attention to the syntax including the parenthesis style brackets.  Note also the use of the = sign here, and not PowerShell's usual -eq.  See more on changing PowerShell's default parameters.

Ordered 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 hash table 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 hash tables.

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

SolarWinds' Orion 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.

Perhaps the NPM's best feature is the way it suggests solutions to network problems.  Its second best feature is 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 take advantage of SolarWinds' offer.

Download a free trial of the Network Performance Monitor.

New PowerShell 3.0 Features For Server Administrators

Microsoft realize Administrators need more features to help manage Windows Server Core.  In particular Administrators need easy ways to automate tasks which will fan out over dozens of virtual servers.  The problem has been that while Windows 8 Server core is more secure, it's harder to administer.  The solution is PowerShell.  But PowerShell 2.0 could do better, as could Windows Server 2008.  So the new dream team will be Windows Server 8 with PowerShell 3.0.

"A small problem times a large frequency, like you get with virtualization, in turn can just drive you crazy. So you've got to have great manageability."   Jeffrey Snover

To achieve these goals PowerShell 3.0 has enhanced workflow capabilities, for instance you can use events to trigger Scheduled jobs.  Furthermore complex PowerShell 3.0 scripts are more likely to complete thanks to more robust WinRM sessions, which proceed or resume in the face of network interruptions. See more on PowerShell 3.0 workflow

New PowerShell 3.0 Features For Developers

Developers can extend their scope by writing cmdlets in .NET, Windows Workflow, there is also a whole set of CIM cmdlets.  For those with the knowledge, there is also the ability to configure REST APIs using PowerShell and OData. 

By using schemas based on MOF (Managed Object Format) developers will find it simpler to write WMI providers.  While PowerShell has always been great at extensibility, these easier working practices arise because WMI is no longer dependent on COM (Component Object Model).

New Feature: PowerShell 3.0 Redirection

PowerShell 3.0 offers the ability to redirect output to text files.  This is particularly useful where an experimental script produces warning messages or needs debugging.

Pipeline   1> 
Error       2>  (Same as PowerShell 2.0)
Warning  3>
Debug     4>

See more of PowerShell 3.0 Redirection.

Earlier Improvements in PowerShell v1.0 --> 2.0

The biggest improvement brought by version 2.0 was remote management.  Being able to run PowerShell commands not only on the local machine, but on networked computers was welcome advance.

While PowerShell is a command-line language, the ISE GUI makes it easier to edit then replay scripts,  I also particularly like the ability to store variations of my scripts on different tabs.

Each new version of PowerShell comes with new built-in cmdlets, for example Send-Mail in Exchange and also numerous new Active directory verb-noun pairing.

Background jobs saves waiting.  You can even run background jobs on a remote computer and store the results locally.

See more tasks for PowerShell »

Summary of What's New In PowerShell 3.0

This page is just to get you started with Windows PowerShell 3.0.  The easiest way to be begin is to download the Windows 8 Customer Preview.  Once installed, 'Pin' the ISE version to the Metro UI; just type 'p' and select Windows PowerShell ISE and away you go!

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

 


See more Microsoft PowerShell v 3.0

PowerShell Tutorials  • What's New in PowerShell 3.0  • PowerShell 3.0 Foreach-Object

PowerShell Show-Command  • Out-GridView -PassThru  • PowerShell Ordered Hash Tables

PowerShell Version 3.0  • PowerShell 3.0 Get-ChildItem  • PowerShell 3.0 Update-Help

 *


Custom Search

Site Home

Guy Recommends: SolarWinds Free IP SLA MonitorSolarwinds IP Sla Monitor

SolarWinds IP SLA Monitor offers so much more than just uncovering network bottlenecks, the real joy is learning about router traffic.

To find out what's happening on the network between your computers and their routers, download your free copy of the of IP SLA Monitor.

Article by: Guy Thomas Copyright © 1999-2012 Computer Performance LTD All rights reserved.

Please report a broken link, or an error to: