Book Image

Instant Windows PowerShell Guide

By : Harshul Patel
Book Image

Instant Windows PowerShell Guide

By: Harshul Patel

Overview of this book

Windows PowerShell has become a booming scripting language over the last couple of years. It has extensive support with an ample number of vendor products, providing a standardized platform for automation and administration. It has massive support for all Microsoft products which creates a layer that can easily automate everything. In the latest version, the PowerShell team has introduced much more functionality with thousands of CMDLETs, part of various modules.This book is a quick reference guide to enable you to get the most out of the latest Windows PowerShell techniques. In this book, you will find new enhancements in the latest version of PowerShell with some helpful examples. This book enables you to quickly move from older versions of PowerShell to Version 3.0 and Version 4.0.This practical, example-oriented book helps you to overcome the difficulty of using and discovering CMDLETs by providing precise information about everything that has been newly introduced in the latest version of Windows PowerShell. It also focuses on the new configuration management system with the help of DSC as a new feature of Windows PowerShell v4.0.You will learn how to use the newly introduced CMDLETs and parameters to perform daily routine tasks. You will also learn how to administer the servers remotely and maintain persistent sessions to provide continuity. You will gain an insight into writing efficient scripts by using various parameters, snippets, and workflows to gain more productivity. You will also be introduced to various modules like CimCmdlets, PSScheduledJob, PSDesiredStateConfiguration, and so on in order to enhance your scripts with the latest instrumentation. Finally this book will make you aware of the capabilities of PowerShell v4.0 and how to fully leverage the functionality introduced in the new version.
Table of Contents (7 chapters)


Windows PowerShell, a booming scripting language, is growing exponentially day-by-day. The enhancements introduced in the latest version make this technology stronger with inexorable growth. It is a must to catch up with the latest version of Windows PowerShell.

Instant Windows PowerShell Guide is a quick reference guide to enable you with Windows PowerShell Versions 3.0 and 4.0 techniques. In this book, you will find new enhancements present in the latest version of PowerShell with an ample number of examples. This book is a cookbook covering quick recipes of new CMDLETs, modules, syntax enhancements, the preference variable introduced, and so on. This book builds a bridge to quickly move from older versions of PowerShell to Versions 3.0 and 4.0.

What this book covers

Windows PowerShell – prerequisites elaborates the need to learn Windows PowerShell as a scripting language with relevant requirements.

Live with help (Simple) describes enhancements done with the latest help system and discovery techniques. Moreover, it suggests ways to update and save help files.

Calculate with the console (Simple) covers new methods and properties introduced in v3.0 with various default objects such as string and integer. It focuses on calculating functionality of the PowerShell console especially with byte units.

Dealing with PSDrive (Simple) describes extensive support of PSDrive with v3.0. It also covers JSON-formatted objects and PSCustomObject types, introduced in v3.0

Administer the system (Intermediate) focuses on a few CMDLETs and parameters which are useful for system administration.

How to import modules to the console (Simple) lets you know how to import modules in the console. It covers module autoloading and logging as key features of v3.0.

Typing enhancements (Intermediate) elaborates typing enhancements with respect to the Where and ForEach objects.

Working with various parameters of Get-Command (Intermediate) elaborates about the parameters of Get-Command in different versions of PowerShell.

Setting default parameter values (Intermediate) describes how to set the default parameter values.

Alias the aliases (Simple) covers various parameters introduced for the Get-Acl and Get-ChildItem CMDLETs.

Operate the data (Intermediate) describes the In and NotIn operators. It also talks about various parameter with the Get-Content and Tee-Object CMDLETs.

Working with the Out-GridView CMDLET (Intermediate) gives details on the different parameters of the Out-GridView CMDLET.

Session scheme (Intermediate) elaborates new CMDLETs and parameters to efficiently deal with Windows PowerShell sessions.

Working remotely (Advanced) covers remoting enhancements with respect to the Invoke-Command CMDLET.

WorkFlow sessions (Advanced) deals with creating an execution sequence by using various command statements.

Script it (Advanced) describes the use of snippets to write scripts quickly and the rebooting feasibility of servers in the middle of a script execution.

WMI versus CIM (Advanced) introduces the CIM CMDLET as the CimCmdlets module. This recipe also shows how it works compared to WMI, used in previous versions.

Job scheduling (Intermediate) elaborates on a dedicated module introduced for PowerShell Job Scheduling named PSScheduledJob.

Understanding Desired State Configuration (Advanced) elaborates about a set of extensions and providers that enable declarative, repeatable deployment and configuration of data center resources. DSC enables us to define the configuration of target nodes (computers or devices) and prevent configuration inconsistencies.

Executing Desired State Configuration (Advanced) describes what needs to be done rather than covering imperative syntax and specifies how a task can be performed.

Exploring various Configuration Providers (Advanced) talks about gathering the information about various DSC resources.

What you need for this book

This book is written by assuming Windows PowerShell Version 3.0 server environments. It needs PowerShell v3.0 that can be availed either with Windows Server 2012 or Windows 8. In few scenarios, it needs PowerShell 4.0 that can be availed with Windows Server 2012 R2. If you deal with older versions of operating systems such as Windows Server 2008 R2 and Windows 7 that have PowerShell v2.0 by default. The upgrade path is given in Windows PowerShell – prerequisites. Keep in mind that the module functionality and outputs vary depending on the environment it has been used in.

Who this book is for

The book is intended for IT professionals who have some knowledge of the previous version of Windows PowerShell. Experience in Microsoft server environment is a plus point.

This is a very useful guide to PowerShell learners who need to quickly update themselves with Windows PowerShell v3.0.


In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "You can use the Get-Help CMDLET immediately after the Update-Help CMDLET to access the updated filesystem."

A block of code is set as follows:

Archive MyArchive
{  Ensure      ="Present" # You can also set Ensure to "Absent"
   Path        ="C:\PS\"
   Destination ="C:\PS\MyScripts" }

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

Service MyService
{  Name       ="MyService"
   StartupType="Automatic" }

Any command-line input or output is written as follows:

PS C :\> 1024MB/1GB
PS C :\> 1000MB/1GB

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "If you use the Copy button to copy code to the clipboard, it appears as follows:"


Warnings or important notes appear in a box like this.


Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on

Customer support

Now that you are a proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.


Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from


Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.


You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.