Introduction
While there are some simple scripts that use only simple Windows PowerShell commands, most scripts use scripting constructs to perform more complex actions. You can use the ForEach construct to process all of the objects in an array. You can use If..Else and Switch constructs to make decisions in your scripts. Finally, there are less common looping constructs such as For, While, and Do..While loops that can be used when appropriate. In this module, you'll learn how to use scripting constructs.
Learning objectives
After completing this module, you'll be able to:
- Describe the syntax of the ForEach construct.
- Describe the syntax of the If construct.
- Describe the syntax of the Switch construct.
- Describe how to use the For construct.
- Describe the other loop constructs.
- Explain how to use Break and Continue.
Prerequisites
Familiarity with:
- Windows networking technologies and implementation
- Windows Server administration, maintenance, and troubleshooting
- Windows PowerShell and its commands to perform specific tasks
- PowerShell cmdlets used for system administration tasks related to Active Directory, network configuration, server administration, and Windows 10 device administration
- Windows PowerShell pipeline, PowerShell providers, and PowerShell drives
- CIM and WMI technologies
- The use of variables, arrays, and hash tables in Windows PowerShell