PowerShell 3.0
PowerShell has become the de facto platform for automating the
administration of Windows-based environments. Built on top of the
common language runtime (CLR) and the Microsoft .NET Framework,
PowerShell has brought a whole new paradigm to how computers running
Windows are configured and managed in enterprise environments.
A new version 3.0 of PowerShell is now included in Windows Server 2012. PowerShell 3.0 is built upon the Windows
Management Framework 3.0, which includes a new WMI provider model that
reduces dependency on COM, a new API for performing standard Common
Information Model (CIM) operations, and the capability of writing new
PowerShell cmdlets in native code. Windows Management Framework 3.0
also includes improvements that make WinRM connections more robust so
they can support long-running tasks and be more resilient against
transient network failure.
PowerShell 3.0 includes many new features that bring added
flexibility and power for managing cloud and multiserver environments.
Many of these key new capabilities are discussed next.
Windows Server 2012 includes hundreds of new PowerShell cmdlets that
help you manage almost every aspect of your private cloud environment.
Note that many cmdlets are only available when the appropriate server
role or feature is installed.
PowerShell 3.0 includes a new cmdlet called Show-Command
that displays a GUI for a command with a simpler overview of any
PowerShell cmdlet. This capability can make it much easier to
understand the syntax of a cmdlet, as opposed to using the Get-Help
cmdlet. For example, if you want to understand the syntax of the Install-ADDSDomain cmdlet used to promote a server to a domain controller, you can type Get-Command Install-ADDSDomain
in the PowerShell console to open the dialog box shown in Figure 5.
PowerShell 3.0 now supports persistent
user-managed sessions (PSSessions) that are not dependent upon the
session in which they were created. By using the New-PSSession cmdlet,
you can create and save a session on a remote server and then
disconnect from the session. The PowerShell commands in the session on
the remote server will then continue to execute, even though you are no
longer connected to the session. If desired, you can reconnect later to
the session from the same or a different computer.
To work with disconnect sessions, you simply do the following:
-
Enable remoting.
-
Create a PSSession to the remote computer.
-
Invoke some PowerShell commands on the remote computer.
-
Verify the completion of the commands on the remote computer.
PowerShell workflows let you write workflows in PowerShell or using Extensible
Application Markup Language (XAML) and then run your workflows as if
they were PowerShell cmdlets. This enables PowerShell to use the
capabilities of the Windows
Workflow Foundation to create long-running management activities that
can be interrupted, suspended, restarted, repeated, and executed in
parallel.
PowerShell workflows are especially valuable in cloud computing
environments because they help you automate administrative operations
by building in repeatability and by increasing robustness and
reliability. They also help increase your servers-to-administrators
ratio by enabling a single administrator to execute a PowerShell
workflow that runs simultaneously on hundreds of servers.
PowerShell 2.0 introduced the concept of background jobs,
which can be scheduled to run asynchronously in the background.
PowerShell 3.0 now includes cmdlets like Start-Job and Get-Job that can
be used to manage these jobs. You can also easily schedule jobs using
the Windows Task Scheduler. This means that you, as the administrator,
can now have full control over when PowerShell scripts execute in your
environment.
PowerShell Web
Access lets you manage the servers in your private cloud from anywhere,
at any time, by running PowerShell commands within a web-based console.
PowerShell Web Access acts as a gateway to provide a web-based
PowerShell console that you can use to manage remote
computers. This lets you run PowerShell scripts and commands even on
computers that don’t have PowerShell installed. All your computer needs
is an Internet connection and a web browser that supports JavaScript
and accepts cookies.
To use PowerShell Web Access, begin by installing it using the Add Roles And Features Wizard, which you can start from Server Manager:
Installing PowerShell Web Access also installs the .NET Framework
4.5 features and the Web Server (IIS) server role, if these are not
already installed on the server. You can also install PowerShell Web
Access with PowerShell by using the Install-WindowsFeature cmdlet.
Next, configure PowerShell Web Access on your server. You can do
this by running the Install-PswaWebApplication cmdlet. You’ll need to
have already installed a server certificate on your server. If you are
trying this in a test environment, however, you can use a self-signed
test certificate, as shown here:
Once you’ve configured PowerShell Web Access, you need to grant users access explicitly by adding authorization rules. You can use the Add-PswaAuthorizationRule cmdlet to do this:
Administrators can then run PowerShell scripts and commands against servers they have been authorized to manage by accessing the gateway from a remote computer. They do this by opening the URL https://<server_name>/pswa in a web browser:
Managing non-Windows systems and devices
You can now use PowerShell cmdlets to manage any standard-compliant
CIM-capable systems, which means you can manage non-Windows servers and
even hardware devices using PowerShell just as you manage Windows.
Some other improvements in PowerShell 3.0 include the following;
-
Delegated administration using RunAs allows commands to be executed
using a delegated set of credentials so that users having limited
permissions can run critical jobs.
-
Improved cmdlet discovery and automatic module loading make it easier to find and run any cmdlets installed on your computer.
-
Show-Command, a cmdlet and ISE Add-On that helps you quickly find
the right cmdlet, view its parameters in a dialog box, and run the
command.
-
Simplified language syntax that make PowerShell commands and scripts
seem a lot less like code and feel more like natural language. For
example, the construct $_. is no longer necessary.
-
The Get-ChildItem cmdlet has new parameters, making it easier to search for files with particular attributes.
-
PowerShell now automatically loads a module when a cmdlet is run from that module.
-
The PowerShell 3.0 Integrated Scripting Environment (ISE) includes
new features that make it easier to code in PowerShell. Examples of
these features include Intellisense, brace-matching, syntax coloring,
Most Recently Used list, snippets, and the ISE Script Explorer.
-
With PowerShell 3.0, you are no longer restricted to the help
content that shipped with Windows Server 2012. Help is now published on
the web as downloadable CAB files.