title: PowerShell 'if' condition
body: <p>Here is a quick little PowerShell blurp that is supposed to get the device's IP address, Service Tag, and MAC address of any active MAC addresses on the device (active meaning there is a connection).</p>
  
  <p>Anyway, if I don't use an <code>if</code> statement, this works perfectly, but if I do, it only executes the first line:</p>
  
  <pre class="lang-powershell prettyprint-override"><code>Test-Connection $computername -count 1 | select @{Name="Computername";Expression={$_.Address}},Ipv4Address
  </code></pre>
  
  <p>If the device is on... and the last line of the device is off.</p>
  
  <pre class="lang-powershell prettyprint-override"><code>Write-Host "Device is offline"
  </code></pre>
  
  <p>Here is my little PowerShell 'script':</p>
  
  <pre class="lang-powershell prettyprint-override"><code>$computername = Read-Host 'Enter Computer Name'
  $online = Test-Connection -Computername $computername -BufferSize 16 -Count 1 -Quiet
  IF ($online -eq "True") {
      Test-Connection $computername -count 1 | select @{Name="Computername";Expression={$_.Address}},Ipv4Address
      Get-WmiObject win32_SystemEnclosure -computername $computername | select serialnumber
      Get-wmiobject -class "Win32_NetworkAdapterConfiguration" -computername $computername |Where{$_.IpEnabled -Match "True"}
  } Else {
      Write-Host "Device is offline"
  }
  </code></pre>
  
  <p>Why does this happen? What might I be doing wrong?</p>