PowerShell Switch: Unterschied zwischen den Versionen

Aus Wiki-WebPerfect
Wechseln zu: Navigation, Suche
(Die Seite wurde neu angelegt: „== Example of a basic PowerShell Switch == <source lang="powershell"> $SwitchName = <Get-...> #Get-Command or something similar Switch ($SwitchName) { "N…“)
(kein Unterschied)

Version vom 4. Juni 2018, 14:20 Uhr

Example of a basic PowerShell Switch

$SwitchName = <Get-...> #Get-Command or something similar
 
Switch ($SwitchName) {
    "Name 1" {$SwitchNumber = 1; break} #Answer to the Get-Command = "Name 1"
    "Name 2" {$SwitchNumber = 2; break} #Answer to the Get-Command = "Name 2"
}
 
Switch ($SwitchNumber) {
    1 {Write-Host "Name 1 is selected, do someting"}
    2 {Write-Host "Name 2 is selected, do someting"}
}