title: Powershell 2.0 - Conditional (Else) not recognized as the name of a cmdlet, function
body: <p>I am trying to produce a powershell script that contains an (IF, Else) statement. Mainly due to compatibility issues in how the different versions call web requests. </p>
  
  <pre><code>V &lt; 2.0 : Uses [System.Net.WebRequest] for HTTP Requests
  </code></pre>
  
  <p>&amp;</p>
  
  <pre><code>V &gt; 2.0 : Uses Invoke-WebRequest 
  </code></pre>
  
  <p>Here is my code : </p>
  
  <pre><code>$pcName="$ENV:COMPUTERNAME";
  $psVers=$host.Version.Major;
  
  if ($psVers -le 2) 
  
              {$request = [System.Net.WebRequest]::Create('http://xxx.co.kr'); 
               $request.Method = "POST"; $request.ContentType = "application/x-www-form-urlencoded"; 
               $bytes = [System.Text.Encoding]::ASCII.GetBytes("pcName=$pcName"); 
               $request.ContentLength = $bytes.Length; $requestStream = $request.GetRequestStream(); 
               $requestStream.Write( $bytes, 0, $bytes.Length ); $requestStream.Close(); 
               $request.GetResponse();}
  
  Else  
              {$POSTdata = @{pcName=$pcName} 
               Invoke-WebRequest -Uri http://xxx.co.kr -Method POST -Body $POSTdata};
  </code></pre>
  
  <p>And here is the error that I am receiving from Powershell v-2.0 : </p>
  
  <pre><code>The term 'Else' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelli
  ng of the name, or if a path was included, verify that the path is correct and try again.
  At line:1 char:5
  + Else &lt;&lt;&lt;&lt;
      + CategoryInfo          : ObjectNotFound: (Else:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
  </code></pre>