Windows PowerShell is a command shell and scripting language
designed to help you achieve all you can from the Windows GUI at the
command line. Windows PowerShell is not new in Windows 8, but it is
becoming more prevalent within the management of the operating system.
You can run cmdlets (pronounced command-lets) to view and manipulate
Windows systems all the way down to Windows Management Instrumentation
(WMI) configurations or run scripts to accomplish its management tasks
in batches. Because Windows
PowerShell is object-based, items that it returns can be treated and
manipulated as objects for greater flexibility in how actions can be
performed when managing systems.
What can Windows PowerShell do for administrators that the GUI cannot?
The GUI can accomplish many things, from modifying user information
to adding mailboxes in Exchange. These tasks can also be accomplished
from within Windows PowerShell. In many cases, for newer versions of
Microsoft technologies, even the tasks performed in the GUI-based
Management utility are actually running Windows PowerShell commands
behind the scenes. In some cases, certain attributes of an object are
not visible within the GUI, so they cannot be managed or accessed this
way. However, Windows PowerShell can access additional attributes of
these objects and populate them with data, providing administrators
with greater access and control within their Windows environments.
Note
MORE INFO DELVING INTO WINDOWS POWERSHELL
If you want to learn more about Windows PowerShell, there are several good sources for the IT professional, including:
-
Windows PowerShell 2.0 Administrator’s Pocket Consultant by William R. Stanek (Microsoft Press, 2009).
-
Windows PowerShell 2.0 Best Practices by Ed Wilson (Microsoft Press, 2009).
Putting Windows PowerShell to work
The following example illustrates how Windows PowerShell can help
you work with items on a certain system and determine which
applications are running.
Fred works for Contoso as an IT help desk employee. He has noticed
that many help desk calls center on applications just do not seem to
start properly; they either present no error or information to the user
or they produce a message stating that an instance of the application
is already running on the computer. He wants to generate a list of
running applications on the user’s computer to see whether he can help
the user close previously running applications before trying to start
new instances of them.
The next time Fred receives a call about this problem, he opens an
Administrator command prompt, types PowerShell.exe, and then runs the
following Windows PowerShell commands to see which applications are
running:
$computer "computername"Get-Process -computername $computer
This brief use of Windows PowerShell displays all the processes running on the specified computer on Fred’s computer screen. The $computer variable is set to the name of a computer that causes the get-process cmdlet to run on that computer.
After Fred has the list of processes, he can work with the person on
the phone to close applications that might not be needed. The user
might be able to do this, or, if an application is frozen and needs
help closing, Fred can use Windows PowerShell to close the application.
$computer = computername
Get-process -computername $computer -process notepad.exe | kill
This command pipes (or passes) any instances of the Notepad.exe
process to the kill alias, which runs the stop-process cmdlet, to stop
the process.
Important
DATA LOSS IS A POSSIBILITY
Forcing processes to close on a computer can cause data loss because it will not gracefully terminate the process.
Windows PowerShell is meant to be an intuitive experience, and it
includes an intuitive (and now online) help system for the cmdlets that
do the behind-the-scenes work. Comment-based help enables authors of
cmdlets, functions, and scripts to include commented lines about
how to interact with their code, which ensures that help is available
whenever needed by just entering the following on the command line, and
then tapping or clicking Enter:
Help <cmdlet|function|script>name
For example, the help get-process cmdlet displays the help for the
get-process cmdlet. This provides not only information about the syntax
of the cmdlet but also example cases about how the item works. This is
how Windows PowerShell teaches its users as they go. Because this
technique is comment help–based, administrators can ask the shell for
help. It does not force them to do a lot of preparation to get started.
Windows 8 includes Windows PowerShell 3.0, which brings
many updates to the code; one of those is online help. This enables
Windows PowerShell to check in with servers at Microsoft to see whether
updates are available to the help files for a cmdlet. When Help is
called, it prompts you to use local help or online help when used
online. The help within Windows PowerShell can provide more information
about cmdlets as its help items are modified.