PowerShell If & Else

 # A Basic If and Else Conditional Statement        $MyNumber="299"
        If ($MyNumber -gt 200){
            Write-host "The Value is Above 200"            
            Write-Host "The Value is Not Above 200"


# Just a bit more complex with a If and a Elseif for doing 2 conditionals. 

        $Myteststring = "ScottHead"
        If ($Myteststring.StartsWith("M")){
            Write-host "It starts with an M"            
            Write-Host "It starts with an S"


# This is called a Nested If Statement       
        If ($MyNumber -gt 200){
           If($MyNumber -lt 300){

            Write-Host "The number is above 200 and less than 300"


2020 | Scott W. Head  |  Sr. Systems Admin | Certified Microsoft Windows Server Administrator