title: Wanted to query remote PCs uptime with powershell
body: <p>I wanting to query machines uptime and decided to try this via powershell but I am struggling to get it to work. Here's what I've done so far:</p>
  
  <pre><code>   function Get-PCUptime {
  
          param (
              [Parameter(ValueFromPipeline=$true)]
              [String]$computer  = (Read-Host "Enter a computer name")
          )
  
  
          $lastboottime = (Get-WmiObject -Class Win32_OperatingSystem -Credential Administrator -comp $computer)
          $sysuptime = (Get-Date) – [System.Management.ManagementDateTimeconverter]::ToDateTime($lastboottime.LastBootUpTime)
  
          if ($lastboottime -ne $NULL){
              Write-Host “System($computer) is Uptime since : ” $sysuptime.days “days” $sysuptime.hours `
              “hours” $sysuptime.minutes “minutes” $sysuptime.seconds “seconds” -Foregroundcolor Gray;
          } 
      }
  </code></pre>
  
  <p>I can't seem to make it work as I am wanting to convert it to days, hours, minutes, etc. </p>
  
  <p>This is the error I receive:</p>
  
  <blockquote>
    <p>Exception calling "ToDateTime" with "1" argument(s): "Specified argument was out of the range of valid values.
    Parameter name: dmtfDate"</p>
  </blockquote>