Home > Store

Windows PowerShell Step by Step, 3rd Edition

eBook

  • Your Price: $46.39
  • List Price: $57.99
  • Includes EPUB and PDF
  • About eBook Formats
  • This eBook includes the following formats, accessible from your Account page after purchase:

    ePub EPUB The open industry format known for its reflowable content and usability on supported mobile devices.

    Adobe Reader PDF The popular standard, used most often with the free Acrobat® Reader® software.

    This eBook requires no passwords or activation to read. We customize your eBook by discreetly watermarking it with your name, making it uniquely yours.

Also available in other formats.

Register your product to gain access to bonus material or receive a coupon.

Description

  • Copyright 2015
  • Dimensions: 7-3/8" x 9"
  • Pages: 704
  • Edition: 3rd
  • eBook
  • ISBN-10: 1-5093-0047-3
  • ISBN-13: 978-1-5093-0047-1

Your hands-on guide to Windows PowerShell scripting fundamentals
Expand your expertise--and teach yourself the fundamentals of Windows PowerShell scripting, including features available in Windows PowerShell 5. If you are an IT professional, power user, or consultant, you’ll get the guidance, exercises, and code you need to master core techniques for automating Windows setup, deployment, and management.
 
Discover how to:

  • Run cmdlets and command-line utilities
  • Administer Windows-based servers and desktops with built-in cmdlets
  • Use providers to access external information
  • Write and run scripts from the Windows ISE
  • Create functions that are easy to maintain
  • Build standardized environments with profiles
  • Automate Windows systems with WMI, CIM cmdlets, and remoting
  • Automate Active Directory Domain Services (AD DS)
  • Debug scripts and handle errors
  • Run commands that survive interruptions
  • Use Desired State Configuration (DSC) to manage software services and their environments
  • Get powerful new modules from PowerShell Gallery
 
About You
This book is for:
  • IT professionals and power users who want to get productive with Windows PowerShell, including new features in Windows PowerShell 5
  • Windows system administrators who want to be more efficient and productive
  • Anyone pursuing Windows PowerShell certifications
No experience with Windows PowerShell or other scripting technologies necessary

Sample Content

Table of Contents

Introduction    xix
Chapter 1: Overview of Windows PowerShell 5.0    1

Understanding Windows PowerShell    1
Using cmdlets    3
Installing Windows PowerShell    3
Deploying Windows PowerShell to down-level operating systems    3
Using command-line utilities    4
Security issues with Windows PowerShell    6
Controlling execution of Windows PowerShell cmdlets    6
Confirming actions    7
Suspending confirmation of cmdlets    8
Working with Windows PowerShell    10
Accessing Windows PowerShell    10
Configuring the Windows PowerShell console    11
Supplying options for cmdlets    11
Working with the help options    12
Exploring commands: Step-by-step exercises    19
Chapter 1 quick reference    22
Chapter 2: Using Windows PowerShell cmdlets    23
Understanding the basics of cmdlets    23
Using the Get-ChildItem cmdlet    24
Obtaining a directory listing    24
Formatting a directory listing by using the Format-List cmdlet    26
Using the Format-Wide cmdlet    27
Formatting a directory listing by using Format-Table    29
Formatting output with Out-GridView    31
Taking advantage of the power of Get-Command    36
Searching for cmdlets by using wildcard characters     36
Using the Get-Member cmdlet    44
Using the Get-Member cmdlet to examine properties and methods    45
Using the New-Object cmdlet    50
Creating and using the wshShell object    50
Using the Show-Command cmdlet    52
Windows PowerShell cmdlet naming helps you learn    54
Windows PowerShell verb grouping    55
Windows PowerShell verb distribution     55
Creating a Windows PowerShell profile    57
Working with cmdlets: Step-by-step exercises    59
Chapter 2 quick reference    63
Chapter 3: Understanding and using Windows PowerShell providers    65
Understanding Windows PowerShell providers    65
Understanding the alias provider    66
Understanding the certificate provider    69
Understanding the environment provider    76
Understanding the filesystem provider    80
Understanding the function provider    85
Using the registry provider to manage the Windows registry    87
The two registry drives    88
The short way to create a new registry key    95
Dealing with a missing registry property    98
Understanding the variable provider    99
Exploring Windows PowerShell providers: Step-by-step exercises    103
Chapter 3 quick reference    107
Chapter 4: Using Windows PowerShell remoting and jobs    109
Understanding Windows PowerShell remoting    109
Classic remoting    109
WinRM     114
Using Windows PowerShell jobs    122
Using Windows PowerShell remoting and jobs: Step-by-step exercises    132
Chapter 4 quick reference    135
Chapter 5: Using Windows PowerShell scripts    137
Why write Windows PowerShell scripts?    137
The fundamentals of scripting    139
Running Windows PowerShell scripts    139
Turning on Windows PowerShell scripting support    140
Transitioning from command line to script    143
Manually running Windows PowerShell scripts    145
Understanding variables and constants    148
Using the While statement    154
Constructing the While statement in Windows PowerShell    154
A practical example of using the While statement    156
Using special features of Windows PowerShell    157
Using the Do...While statement    157
Using the range operator    158
Operating over an array    158
Casting to ASCII values    159
Using the Do...Until statement    160
Comparing the Windows PowerShell Do...Until statement with VBScript    160
Using the Windows PowerShell Do statement    161
The For statement    162
Using the For statement     163
Using the Foreach statement    164
Exiting the Foreach statement early    166
Using the If statement    168
Using assignment and comparison operators    169
Evaluating multiple conditions    170
The Switch statement    171
Using the Switch statement    172
Controlling matching behavior    174
Creating multiple folders: Step-by-step exercises    174
Chapter 5 quick reference    177
Chapter 6: Working with functions    179
Understanding functions    179
Using functions to provide ease of code reuse    186
Including functions in the Windows PowerShell environment    188
Using dot-sourcing    188
Using dot-sourced functions    190
Adding help for functions    191
Using a here-string object for help    192
Using two input parameters    194
Using a type constraint in a function    198
Using more than two input parameters    200
Using functions to encapsulate business logic    202
Using functions to provide ease of modification    204
Understanding filters    209
Creating a function: Step-by-step exercises    213
Chapter 6 quick reference    216
Chapter 7: Creating advanced functions and modules    217
The [cmdletbinding] attribute    217
Easy verbose messages    218
Automatic parameter checks    219
Adding support for the -WhatIf switch parameter    222
Adding support for the -Confirm switch parameter    223
Specifying the default parameter set    224
The Parameter attribute    224
The Mandatory parameter property    225
The Position parameter property    226
The ParameterSetName parameter property    227
The ValueFromPipeline property    228
The HelpMessage property    229
Understanding modules    230
Locating and loading modules    230
Installing modules    235
Creating a module    246
Creating an advanced function and installing a module: Step-by-step exercises    253
Chapter 7 quick reference    257
Chapter 8: Using the Windows PowerShell ISE    259
Running the Windows PowerShell ISE    259
Navigating the Windows PowerShell ISE    260
Working with the script pane    263
Using tab expansion and IntelliSense    264
Working with Windows PowerShell ISE snippets    266
Using Windows PowerShell ISE snippets to create code    266
Creating new Windows PowerShell ISE snippets    268
Removing user-defined Windows PowerShell ISE snippets    269
Using the Commands add-on and snippets: Step-by-step exercises    270
Chapter 8 quick reference    274
Chapter 9: Working with Windows PowerShell profiles    275
Six different Windows PowerShell profiles    275
Understanding the six Windows PowerShell profiles    276
Examining the $profile variable    276
Determining whether a specific profile exists    278
Creating a new profile    279
Design considerations for profiles    279
Using one or more profiles    281
Using the All Users, All Hosts profile    283
Using your own file    284
Grouping similar functionality into a module    285
Where to store the profile module    285
Creating and adding functionality to a profile: Step-by-step exercises    286
Chapter 9 quick reference    289
Chapter 10: Using WMI    291
Understanding the WMI model    292
Working with objects and namespaces    292
Listing WMI providers    297
Working with WMI classes    298
Querying WMI    301
Obtaining service information: Step-by-step exercises    306
Chapter 10 quick reference    312
Chapter 11: Querying WMI    313
Alternate ways to connect to WMI    313
Returning selective data from all instances    321
Selecting multiple properties    322
Choosing specific instances    325
Using an operator    327
Shortening the syntax    330
Working with software: Step-by-step exercises    332
Chapter 11 quick reference     339
Chapter 12: Remoting WMI    341
Using WMI against remote systems    341
Supplying alternate credentials for the remote connection    342
Using Windows PowerShell remoting to run WMI    345
Using CIM classes to query WMI classes    346
Working with remote results    348
Reducing data via Windows PowerShell parameters    352
Reducing data via WQL query    353
Running WMI jobs    355
Using Windows PowerShell remoting and WMI: Step-by-step exercises    357
Chapter 12 quick reference     360
Chapter 13: Calling WMI methods on WMI classes    361
Using WMI cmdlets to execute instance methods    361
Using the Terminate method directly    363
Using the Invoke-WmiMethod cmdlet    365
Using the [wmi] type accelerator    366
Using WMI cmdlets to work with static methods    367
Executing instance methods: Step-by-step exercises    370
Chapter 13 quick reference     373
Chapter 14: Using the CIM cmdlets    375
Using the CIM cmdlets to explore WMI classes    375
Using the Get-CimClass cmdlet and the -ClassName parameter    375
Finding WMI class methods    377
Filtering classes by qualifier    379
Retrieving WMI instances    383
Reducing returned properties and instances    383
Cleaning up output from the command    384
Working with associations    385
Retrieving WMI instances: Step-by-step exercises    392
Chapter 14 quick reference     394
Chapter 15: Working with Active Directory    395
Creating objects in Active Directory    395
Creating an OU    395
ADSI providers    397
LDAP names    399
Creating users    405
What is user account control?    408
Working with users    409
Creating multiple OUs: Step-by-step exercises    423
Chapter 15 quick reference    429
Chapter 16: Working with the AD DS module    431
Understanding the Active Directory module    431
Installing the Active Directory module    431
Getting started with the Active Directory module    433
Using the Active Directory module    433
Finding the FSMO role holders    435
Discovering Active Directory    439
Renaming Active Directory sites    442
Managing users    443
Creating a user    446
Finding and unlocking Active Directory user accounts    447
Finding disabled users    449
Finding unused user accounts    451
Updating Active Directory objects: Step-by-step exercises    454
Chapter 16 quick reference    457
Chapter 17: Deploying Active Directory by using Windows PowerShell    459
Using the Active Directory module to deploy a new forest    459
Adding a new domain controller to an existing domain    465
Adding a read-only domain controller    468
Installing domain controller prerequisites and adding to a forest: Step-by-step exercises    470
Chapter 17 quick reference    472
Chapter 18: Debugging scripts    473
Understanding debugging in Windows PowerShell    473
Understanding the three different types of errors    473
Using the Set-PSDebug cmdlet     479
Tracing the script    479
Stepping through the script    483
Enabling strict mode    488
Debugging the script    492
Setting breakpoints    492
Setting a breakpoint on a line number    492
Setting a breakpoint on a variable    495
Setting a breakpoint on a command    499
Responding to breakpoints    501
Listing breakpoints    503
Enabling and disabling breakpoints    504
Deleting breakpoints    504
Debugging a function: Step-by-step exercises    505
Chapter 18 quick reference    509
Chapter 19: Handling errors    511
Handling missing parameters    511
Creating a default value for a parameter    512
Making the parameter mandatory    513
Limiting choices    514
Using PromptForChoice to limit selections    514
Using Test-Connection to identify computer connectivity    516
Using the -contains operator to examine the contents of an array    517
Using the -contains operator to test for properties    519
Handling missing rights     521
Using an attempt-and-fail approach    522
Checking for rights and exiting gracefully    522
Handling missing WMI providers    523
Handling incorrect data types    532
Handling out-of-bounds errors    536
Using a boundary-checking function    536
Placing limits on the parameter    537
Using Try...Catch...Finally    538
Catching multiple errors    541
Using PromptForChoice to limit selections and using Try…Catch…Finally: Step-by-step exercises    544
Chapter 19 quick reference     546
Chapter 20: Using the Windows PowerShell workflow    547
Why use workflows?    547
Workflow requirements    548
A simple workflow    548
Parallel PowerShell    549
Workflow activities    552
Windows PowerShell cmdlets as activities    553
Disallowed core cmdlets    554
Non-automatic cmdlet activities    554
Parallel activities    555
Checkpointing Windows PowerShell workflow    556
Understanding checkpoints    556
Placing checkpoints    556
Adding checkpoints    556
Adding a sequence activity to a workflow    559
Creating a workflow and adding checkpoints: Step-by-step exercises    561
Chapter 20 quick reference    563
Chapter 21: Managing Windows PowerShell DSC    565
Understanding Desired State Configuration    565
The DSC process    566
Configuration parameters    568
Setting dependencies    570
Controlling configuration drift    571
Modifying environment variables    573
Creating a DSC configuration and adding a dependency: Step-by-step exercises    576
Chapter 21 quick reference    580
Chapter 22: Using the PowerShell Gallery    581
Exploring the PowerShell Gallery    581
Configuring and using PowerShell Get    583
Installing a module from the PowerShell Gallery    585
Configuring trusted installation locations    586
Uninstalling a module     586
Searching for and installing modules from the PowerShell Gallery: Step-by-step exercises    587
Chapter 22 quick reference    589
Appendix A: Windows PowerShell scripting best practices    591
Appendix B: Regular expressions quick reference    599
Index    603
About the author    631



Updates

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020