title: check if the system is down or not
body: <p>this is the script I wrote to check whether a system with the given IP is up or down in Linux:</p>
  
  <pre class="lang-bash prettyprint-override"><code>#!/bin/bash
  clear
  x=`date`
  read -p "please enter ip:" ip
  ping -c1 $ip&gt;/dev/null 2&gt;/dev/null
  if [$?!= 0]; then
    echo $ip on $x | mail -s "server is down…" admin
  else
    echo "server is up"
  fi
  </code></pre>
  
  <p>I want to edit this for PowerShell so, this is my code:</p>
  
  <pre class="lang-bsh prettyprint-override"><code>$x = date
  $IP = Read-Host -Prompt "Please Enter IP"
  ping $IP -n 1 &gt; null 2&gt;&amp;1
  if ($? -ne 0) {
      echo "$IP the server is Down on $x"
  } else {
      echo "everything is fine"
  }
  </code></pre>
  
  <p>but it always outputs <code>"the server is Down"</code> regardless of what the IP is.</p>