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