'Powershell Menu
I am looking to have this menu that I have been frankensteining and learning powershell while doing so, I am a systems admin I and trying to learn PS and more networking to grow in career. Any edits and advice is much appreciated I just bought a ps book and youtubing a lot!
Function Menu {
Clear-Host
Do
{
Clear-Host
Write-Host -Object 'Please choose an option'
Write-Host -Object '**********************'
Write-Host -Object 'Scripts to run' -ForegroundColor Yellow
Write-Host -Object '**********************'
Write-Host -Object '1. Ping PC '
Write-Host -Object ''
Write-Host -Object '2. Restart ELP Desktops '
Write-Host -Object ''
Write-Host -Object '3. Restart NOVI Desktops '
Write-Host -Object ''
Write-Host -Object '4. Check PC Storage '
Write-Host -Object ''
Write-Host -Object 'Q. Quit'
Write-Host -Object $errout
$Menu = Read-Host -Prompt '(0-4 or Q to Quit)'
switch ($Menu)
{
1 {
$Computer = Read-Host Please Enter Host name
Get-WMIObject Win32_NetworkAdapterConfiguration -Computername $Computer | `
Where-Object {$_.IPEnabled -match "True"} | `
Select-Object -property DNSHostName,ServiceName,@{N="DNSServerSearchOrder";
E={"$($_.DNSServerSearchOrder)"}},
@{N='IPAddress';E={$_.IPAddress}},
@{N='DefaultIPGateway';E={$_.DefaultIPGateway}} | FT
pause
}
2
{
restart-computer -ComputerName ######## -force
}
3
{
restart-computer -ComputerName ######## -force
}
4
{
# Ask for computer name
$Computer = Read-Host "Please Enter Host name"
Get-WmiObject Win32_LogicalDisk -ComputerName $Computer -Filter DriveType=3 | Select-
Object DeviceID, FreeSpace, Size |pause
}
Q
{
Exit
}
default
{
$errout = 'Invalid option please try again........Try 0-4 or Q only'
}
}
}
until ($Menu -eq 'q')
}
# Launch The Menu
Menu
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
