PS: Script Menu

PS: Script Menu

Please see below snippet to build a looping menu until option is entered

Write-Host '--- Menu Header ---' -foregroundcolor yellow
[int]$xMenuChoiceA = 0
while ( $xMenuChoiceA -lt 1 -or $xMenuChoiceA -gt 2 )
{
# Write to Console Menu Options #
Write-host '1. Restart Computer' -ForegroundColor Yellow
Write-host '2. Show IP Configuration' -ForegroundColor Yellow
Write-Host 'Please enter an option 1 to 2...' -foregroundcolor yellow
[Int]$xMenuChoiceA = read-host }
# Switch Options and Command Sets #
Switch( $xMenuChoiceA ){
1{
# Restart Computer Command #
restart-computer
}
2{
# Display IP Configuration #
ipconfig /all
}
}
Advertisements