Home > Sample chapters

Overview of Windows PowerShell 5.0

This chapter from "Windows PowerShell Step by Step, 3rd Edition" covers the basic use and capabilities of Windows PowerShell, how to install Windows PowerShell, how to use basic command-line utilities inside Windows PowerShell and access Windows PowerShell help, and run and get help on basic Windows PowerShell cmdlets.

After completing this chapter, you will be able to

  • Understand the basic use and capabilities of Windows PowerShell.
  • Install Windows PowerShell.
  • Use basic command-line utilities inside Windows PowerShell.
  • Use Windows PowerShell help.
  • Run basic Windows PowerShell cmdlets.
  • Get help on basic Windows PowerShell cmdlets.

The release of Windows PowerShell 5.0 continues to offer real power to the Windows network administrator. Combining the power of a full-fledged scripting language with access to command-line utilities, Windows Management Instrumentation (WMI), and even Microsoft Visual Basic Scripting Edition (VBScript), Windows PowerShell provides real power and ease. The implementation of hundreds of cmdlets and advanced functions provides a rich ecosystem that makes sophisticated changes as simple as a single line of easy-to-read code. As part of the Microsoft Common Engineering Criteria, Windows PowerShell is the management solution for the Windows platform.

Understanding Windows PowerShell

Perhaps the biggest obstacle for a Windows network administrator in migrating to Windows PowerShell 5.0 is understanding what Windows PowerShell actually is. In some respects, it is a replacement for the venerable CMD (command) shell. In fact, on Windows Server–based computers running Server Core, it is possible to replace the CMD shell with Windows PowerShell so that when the server starts up, it uses Windows PowerShell as the interface.

As shown here, after Windows PowerShell launches, you can use cd to change the working directory, and then use dir to produce a directory listing in exactly the same way you would perform these tasks from the CMD shell.

PS C:\Windows\System32> cdPS C:\> dir


    Directory: C:

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        7/10/2015   7:07 PM                FSO
d-----         7/9/2015   5:24 AM                PerfLogs
d-r---         7/9/2015   6:59 AM                Program Files
d-r---        7/10/2015   7:27 PM                Program Files (x86)
d-r---        7/10/2015   7:18 PM                Users
d-----        7/10/2015   6:00 PM                Windows


PS C:\>

You can also combine traditional CMD interpreter commands with other utilities, such as fsutil. This is shown here.

PS C:\> md c:\test


    Directory: C:

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        7/11/2015  11:14 AM                test


PS C:\> fsutil file createnew c:\test\myfile.txt 1000
File c:\test\myfile.txt is created
PS C:\> cd c:\test
PS C:\test> dir


    Directory: C:\test


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        7/11/2015  11:14 AM           1000 myfile.txt


PS C:\test>

The preceding two examples show Windows PowerShell being used in an interactive manner. Interactivity is one of the primary features of Windows PowerShell, and you can begin to use Windows PowerShell interactively by opening a Windows PowerShell prompt and entering commands. You can enter the commands one at a time, or you can group them together like a batch file. I will discuss this later because you will need more information to understand it.

Using cmdlets

In addition to using Windows console applications and built-in commands, you can also use the cmdlets (pronounced commandlets) that are built into Windows PowerShell. Cmdlets can be created by anyone. The Windows PowerShell team creates the core cmdlets, but many other teams at Microsoft were involved in creating the hundreds of cmdlets that were included with Windows 10. They are like executable programs, but they take advantage of the facilities built into Windows PowerShell, and therefore are easy to write. They are not scripts, which are uncompiled code, because they are built using the services of a special Microsoft .NET Framework namespace. Windows PowerShell 5.0 comes with about 1,300 cmdlets on Windows 10, and as additional features and roles are added, so are additional cmdlets. These cmdlets are designed to assist the network administrator or consultant to take advantage of the power of Windows PowerShell without having to learn a scripting language. One of the strengths of Windows PowerShell is that cmdlets use a standard naming convention that follows a verb-noun pattern, such as Get-Help, Get-EventLog, or Get-Process. The cmdlets that use the get verb display information about the item on the right side of the dash. The cmdlets that use the set verb modify or set information about the item on the right side of the dash. An example of a cmdlet that uses the set verb is Set-Service, which can be used to change the start mode of a service. All cmdlets use one of the standard verbs. To find all of the standard verbs, you can use the Get-Verb cmdlet. In Windows PowerShell 5.0, there are nearly 100 approved verbs.

Installing Windows PowerShell

Windows PowerShell 5.0 comes with Windows 10 Client. You can download the Windows Management Framework 5.0 package, which contains updated versions of Windows Remote Management (WinRM), WMI, and Windows PowerShell 5.0, from the Microsoft Download Center. Because Windows 10 comes with Windows PowerShell 5.0, there is no Windows Management Framework 5.0 package available for download—it is not needed. In order to install Windows Management Framework 5.0 on Windows 7, Windows 8.1, Windows Server 2008 R2, Windows Server 2012, and Windows Server 2012 R2, they all must be running the .NET Framework 4.5.

Deploying Windows PowerShell to down-level operating systems

After Windows PowerShell is downloaded from http://www.microsoft.com/downloads, you can deploy it to your enterprise by using any of the standard methods.

Here are few of the methods that you can use to accomplish Windows PowerShell deployment:

  • Create a Microsoft Systems Center Configuration Manager package and advertise it to the appropriate organizational unit (OU) or collection.
  • Create a Group Policy Object (GPO) in Active Directory Domain Services (AD DS) and link it to the appropriate OU.
  • Approve the update in Software Update Services (SUS), when available.
  • Add the Windows Management Framework 5.0 packages to a central file share or webpage for self-service.

If you are not deploying to an entire enterprise, perhaps the easiest way to install Windows PowerShell is to download the package and step through the wizard.