Using Conditional Statements in Windows PowerShell 2

As you automate your Windows operating system with PowerShell 2, you use conditional statements to run different script blocks depending on a specific condition, usually using an if/else or switch statement. Following are examples of conditional statements:


$size = "M"
if ($size -eq "S") {
Write-Host "Small"
} elseif ($size -eq "M") {
Write-Host "Medium"
} else {
Write-Host "Large"
}
$size = "M"
switch ($size)
{
"S" {Write-Host "Small"}
"M" {Write-Host "Medium"}
default {Write-Host "Large"}
}



dummies

Source:http://www.dummies.com/how-to/content/using-conditional-statements-in-windows-powershell.html

No comments:

Post a Comment