Conditional statements in windows powershell scripting

There are 2 types of conditional statements in Powershell.
  • if …. else
  • switch

if…..else statement

Here is an example on if…else statement.
 

$a=11

if ($a%2 -eq 0)
{
echo “a is even”
}
else
{
echo “a is odd”
}

switch statement

Here is an example on switch statement.
 
$a=2

switch ($a)
{
1 {echo “case 1”}
2 {echo “case 2”}
default {echo “default case”}
}

Web development and Automation testing

solutions delivered!!