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.
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.
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:
Guy
Recommends: WMI Monitor and It's Free!
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.
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.
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
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:
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.
Guy Recommends: SolarWinds' Free 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:
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.0
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...
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.
Guy Recommends: A Free Trial of the Network Performance Monitor
(NPM)
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.
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.
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.
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