Advertisement
Online Test Banks
Score higher
See Online Test Banks
eLearning
Learning anything is easy
Browse Online Courses
Mobile Apps
Learning on the go
Explore Mobile Apps
Dummies Store
Shop for books and more
Start Shopping

Using Conditional Statements in Windows PowerShell 2

Part of the Windows PowerShell 2 For Dummies Cheat Sheet

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"}
}
  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
Advertisement
Advertisement

Inside Dummies.com

Dummies.com Sweepstakes

Win an iPad Mini. Enter to win now!