The
introduction of WSH as a standard in the Windows operating system
offered a robust alternative to DOSShell scripting. Unfortunately, WSH
presented a number of challenges, discussed in the preceding section.
Furthermore, WSH didn’t offer the CLI shell experience that UNIX and
Linux administrators had enjoyed for years, resulting in Windows
administrators being made fun of by the other chaps for the lack of a
CLI shell and its benefits.
Luckily, Jeffrey Snover
(the architect of PowerShell) and others on the PowerShell team realized
that Windows needed a strong, secure, and robust CLI shell for systems
management. Enter PowerShell. PowerShell was designed as a shell with
full access to the underpinnings of Windows via the .NET Framework,
Component Object Model (COM) objects, and other methods. It also
provided an execution environment that’s familiar, easy, and secure.
PowerShell is aptly named, as it puts the power into the Windows shell.
For users wanting to automate their Windows systems, the introduction of
PowerShell was exciting because it combined “the power of WSH with the
warm-fuzzy familiarity of a CLI shell.”
PowerShell provides a
powerful native scripting language, so scripts can be ported to all
Windows systems without worrying about whether a particular language
interpreter is installed. In the past, an administrator might have gone
through the rigmarole of scripting a solution with WSH in Perl, Python,
VBScript, JScript, or another language, only to find that the next
system that they worked on didn’t have that interpreter installed. At
home, users can put whatever they want on their systems and maintain
them however they see fit, but in a workplace, that option isn’t always
viable. PowerShell solves that problem by removing the need for
nonnative interpreters. It also solves the problem of wading through
websites to find command-line equivalents for simple GUI shell
operations and coding them into .cmd files. Last, PowerShell addresses
the WSH security problem by providing a platform for secure Windows
scripting. It focuses on security features such as script signing, lack
of executable extensions, and execution policies (which are restricted
by default).
For anyone who needs to
automate administration tasks on a Windows system or a Microsoft
platform, PowerShell provides a much-needed injection of power. As such,
for Windows systems administrators or scripters, becoming a PowerShell
expert is highly recommended. After all, PowerShell can now be used to
efficiently automate management tasks for Windows, Active Directory,
Terminal Services, SQL Server, Exchange Server, Internet Information
Services (IIS), and even a number of different third-party products.
As such, PowerShell
is the approach Microsoft had been seeking as the automation and
management interface for their products. Thus, PowerShell is now the
endorsed solution for the management of Windows-based systems and server
products. Over time, PowerShell could even possibly replace the current
management interfaces, such as cmd.exe,
WSH, CLI tools, and so on, while becoming even further integrated into
the Windows operating system. The trend toward this direction can be
seen with the release of Windows Server 2008 R2 and Windows 7, in which
PowerShell is part of the operating system.
PowerShell Uses
In Windows, an administrator can complete a number of tasks using PowerShell. The following list is a sampling of these tasks:
Manage the file system— To create, delete, modify, and set permissions for files and folders. Manage services— To list, stop, start, restart, and even modify services. Manage processes— To list (monitor), stop, and start processes. Manage the Registry— To list (monitor), stop, and start processes. Use Windows Management Instrumentation (WMI)— To manage not only Windows, but also other platforms such as IIS and Terminal Services. Use existing Component Object Model (COM) objects— To complete a wide range of automation tasks. Manage a number of Windows roles and features— To add or remove roles and features.
PowerShell Features
PowerShell is a
departure from the current management interfaces in Windows. As such, it
has been built from the ground up to include a number of features that
make CLI and script-based administration easier. Some of PowerShell’s
more key features are as follows:
It has 240 built-in command-line tools (referred to as cmdlets). The scripting language is designed to be readable and easy to use. PowerShell
supports existing scripts, command-line tools, and automation
interfaces, such as WMI, ADSI, .NET Framework, ActiveX Data Objects
(ADO), and so on. It follows a strict naming convention for commands based on a verb-noun format. It
supports a number of different Windows operating systems: Windows XP
SP2 or later, Windows Server 2003 SP1 or later, Windows Vista, Windows
Server 2008, and now Windows Server 2008 R2 and Windows 7. It
provides direct “access to and navigation of” the Windows Registry,
certificate store, and file system using a common set of commands. PowerShell is object based, which allows data (objects) to be piped between commands. It
is extensible, which allows third parties (as noted earlier) to build
upon and extend PowerShell’s already rich interfaces for managing
Windows and other Microsoft platforms.
PowerShell 2.0 Enhancements
Windows
Server 2008 R2 has the Windows PowerShell 2.0 version built in to the
operating system. In this version of PowerShell, a number of
enhancements have been made to both PowerShell itself and the ability
for managing Windows Server 2008 R2’s roles and features. The following
is a summary for some of the improvements in PowerShell 2.0 :
The number of built-in cmdlets has nearly doubled from 130 to 240. PowerShell
2.0 now includes the ability to manage a number of roles and features
such as the Active Directory Domain Services, Active Directory Rights
Management Services, AppLocker, Background Intelligent Transfer Service
[BITS], Best Practices Analyzer, Failover Clustering [WSFC], Group
Policy, Internet Information Services [IIS], Network Load Balancing
[NLB], Remote Desktop Services [RDS], Server Manager, Server Migration,
and Windows Diagnostics roles and features. PowerShell
2.0 also includes the introduction of the Windows PowerShell debugger.
Using this feature, an administrator can identify errors or
inefficiencies in scripts, functions, commands, and expressions while
they are being executed through a set of debugging cmdlets or the
Integrated Scripting Environment (ISE). The
PowerShell Integrated Scripting Environment (ISE) is a multi-tabbed
GUI-based PowerShell development interface. Using the ISE, an
administrator can write, test, and debug scripts. The ISE includes such
features as multiline editing, tab completion, syntax coloring,
selective execution, context-sensitive help, and support for
right-to-left languages. Background jobs enable administrators to execute commands and scripts asynchronously. Also
through the inclusion of script functions, administrators can now
create their own cmdlets without having to write and compile the cmdlet
using a managed-code language like C#. PowerShell
2.0 also includes a new powerful feature, called modules, which allows
packages of cmdlets, providers, functions, variables, and aliases to be
bundled and then easily shared with others. The
lack of remote command support has also been addressed in PowerShell
2.0 with the introduction of remoting. This feature enables an
administrator to automate the management of many remote systems through a
single PowerShell console.
However, with all of
these features, the most important advancement that is found in
PowerShell 2.0 is the focus on what is called the Universal Code
Execution model. The core concept in this model is flexibility over how
expressions, commands, and scriptblocks are executed across one or more
machines.
|