Book Image

Mastering Windows PowerShell Scripting

By : Brenton J.W. Blawat
Book Image

Mastering Windows PowerShell Scripting

By: Brenton J.W. Blawat

Overview of this book

Table of Contents (22 chapters)
Mastering Windows PowerShell Scripting
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Combining the use of functions, switches, and loops


There may be instances where you will want to combine the use of the different structures explained in this chapter. The example that you will create is a simple menu system that can be modified for use within your scripts. This script will prompt for your interaction and perform actions based on your response, as shown here:

# A Menu System for Use With This Example
Function menu-system {
    Write-host "*********************************************"
    Write-Host "* Please Make A Selection Below:"
    Write-Host "*"
    Write-Host "* [1] Backup User Permissions."
    Write-host "*"
    Write-Host "* [2] Delete User Permissions."
    Write-host "*"
    Write-Host "* [3] Restore User Permissions."
    Write-host "*"
    Write-host "*********************************************"
    Write-host ""
    Write-host "Please Make A Selection:"
    # Prompt for a User Input.
    $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
    # A Switch...