title: Executing CHKDSK for remote computer in Powershell
body: <p>This is what I have come up with but it says "Drive Letter does not exist"</p>
  
  <pre><code>clear
  $server = Read-Host "Enter server name"
  $driveletter = Read-Host "Enter Drive Letter"
  $disks = Get-WmiObject -ComputerName $server -Class Win32_LogicalDisk -Filter  ("DeviceID='" + $driveletter+":'")
  
  $FixErrors          = $false    # does not fix errors 
  $VigorousIndexCheck = $true     # performs a vigorous check of the indexes
  $SkipFolderCycle    = $false    # does not skip folder cycle checking.
  $ForceDismount      = $false    # will not force a dismount (to enable errors to be   fixed)
  $RecoverBadSecors   = $false    # does not recover bad sectors
  $OKToRunAtBootup    = $false    # runs now, vs at next bootup
  
  foreach($disk in $disks) 
  {
      $deviceID = $disk.DeviceID
      Write-Host $deviceID
  
      If ($deviceID -eq $driveletter)
      {
           $res = $c.chkdsk($FixErrors, 
                      $VigorousIndexCheck, 
                      $SkipFolderCycle, 
                      $ForceDismount,
                       $RecoverBadSecors, 
                     $OKToRunAtBootup)
  
            $result = $res.ReturnValue
            Write-Host $result
  
  }
  Else
  {
      "Drive letter does not exist"
  }
  }
  </code></pre>
  
  <p>The server I entered is pinging fine and returns the drive letter also but it is not returning the chkdsk return value. How can I get the chkdsk return value?</p>