none
Run Powershell Chkdsk script on multiple servers RRS feed

  • Question

  • I wrote a powershell chkdsk script which runs chkdsk on multiple servers and for all the drives in it and return the values. I've diverted the output to a notepad. The issue is when I run the script it is throwing Unknown error code '3' for few servers and in few servers it fails to run. What can cause this problem?
    Sunday, July 10, 2016 10:30 AM

Answers

  • You will find that running ChkDsk remotely on the system drive is not very useful.  I recommend using Group Policy to force a chkdsk on the system drive.

    There is no work around as the WMI limits are hard coded.


    \_(ツ)_/

    • Marked as answer by H_Karthik Monday, July 11, 2016 1:42 PM
    Monday, July 11, 2016 1:26 PM

All replies

  • PS D:\scripts> net helpmsg 3

    The system cannot find the path specified.


    \_(ツ)_/

    Sunday, July 10, 2016 10:57 AM
  • Thanks for replying.. Here is the script that I'm trying to execute - 

    $Username = 'user'
    $Password = 'user'
    $pass = ConvertTo-SecureString -AsPlainText $Password -Force
    $Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$pass

    $servers = Get-Content "C:\chkdsk\chkdsk_New\servers.txt"
     
    $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

    Get-Date | Out-File "C:\chkdsk\chkdsk_New\chkdsk_Result_$((Get-Date).ToString('MM-dd-yyyy')).txt" -Append

    Write-Output "CHKDSK RETURN VALUES:-" | Out-File "C:\chkdsk\chkdsk_New\chkdsk_Result_$((Get-Date).ToString('MM-dd-yyyy')).txt" -Append
    Write-Output "Success - 0 Chkdsk Completed" | Out-File "C:\chkdsk\chkdsk_New\chkdsk_Result_$((Get-Date).ToString('MM-dd-yyyy')).txt" -Append
    Write-Output "Success - 1 Locked and chkdsk scheduled on reboot" | Out-File "C:\chkdsk\chkdsk_New\chkdsk_Result_$((Get-Date).ToString('MM-dd-yyyy')).txt" -Append
    Write-Output "Failure - 2 Unknown file system" | Out-File "C:\chkdsk\chkdsk_New\chkdsk_Result_$((Get-Date).ToString('MM-dd-yyyy')).txt" -Append
    Write-Output "Failure - 3 Unknown error" | Out-File "C:\chkdsk\chkdsk_New\chkdsk_Result_$((Get-Date).ToString('MM-dd-yyyy')).txt" -Append
    Write-Output "Failure - 4 Unsupported File System" | Out-File "C:\chkdsk\chkdsk_New\chkdsk_Result_$((Get-Date).ToString('MM-dd-yyyy')).txt" -Append

    foreach($server in $servers)
    {
    if(Test-Connection -ComputerName $server -Quiet)
    {
    Write-Output "++++++++++$server++++++++++" | Out-File "C:\chkdsk\chkdsk_New\chkdsk_Result_$((Get-Date).ToString('MM-dd-yyyy')).txt" -Append
    $OS = (Get-Wmiobject -class Win32_OperatingSystem -computername $server).caption
    Write-Output "++++++++++++++++++++++++++++++++++++++++++++" $OS "++++++++++++++++++++++++++++++++++++++++++++" | Out-File "C:\chkdsk\chkdsk_New\chkdsk_Result_$((Get-Date).ToString('MM-dd-yyyy')).txt" -Append
     
    Foreach ($LogicalDisk in (Get-WmiObject Win32_logicaldisk -ComputerName $server -Authentication Default -Credential $Cred))
    {
    $LogicalDisk.DeviceID | Out-File "C:\chkdsk\chkdsk_New\chkdsk_Result_$((Get-Date).ToString('MM-dd-yyyy')).txt" -Append
    $res = $LogicalDisk.Chkdsk($FixErrors, 
                  $VigorousIndexCheck, 
                  $SkipFolderCycle, 
                  $ForceDismount,
                  $RecoverBadSecors, 
                  $OKToRunAtBootup)
    $res.ReturnValue | Out-File "C:\chkdsk\chkdsk_New\chkdsk_Result_$((Get-Date).ToString('MM-dd-yyyy')).txt" -Append
    }
    }
    else
    {
    Write-Output "+++++++++++++$server is not-reachable++++++++++++++" | Out-File "C:\chkdsk\chkdsk_New\chkdsk_Result_$((Get-Date).ToString('MM-dd-yyyy')).txt" -Append
    }
    }#Forloop


    Sunday, July 10, 2016 11:56 AM
  • Also I need to run this script in read only mode as we've critical application servers in the environment. Script output format seems something like this -

    aturday, July 09, 2016 3:30:09 AM


    CHKDSK RETURN VALUES:-
    Success - 0 Chkdsk Completed
    Success - 1 Locked and chkdsk scheduled on reboot
    Failure - 2 Unknown file system
    Failure - 3 Unknown error
    Failure - 4 Unsupported File System
    ++++++++++Server1++++++++++
    ++++++++++++++++++++++++++++++++++++++++++++
    Microsoft Windows Server 2008 R2 Standard 
    ++++++++++++++++++++++++++++++++++++++++++++
    A:
    2
    C:
    3
    D:
    2
    E:
    0

    In this for C drive the script returns value 3 which is Unknown error. But there is no issue with the drive and I'm not sure why it fails to run chkdsk for the particular drive. The same way I'm getting errors for many servers. 

    Sunday, July 10, 2016 12:00 PM
  • Please read the following post first, from right at the top of this forum:

    This forum is for scripting questions rather than script requests

    You need to focus on one specific question. The purpose of this forum is not to fix/rewrite scripts on request.


    -- Bill Stewart [Bill_Stewart]

    Sunday, July 10, 2016 12:20 PM
    Moderator
  • Thanks Bill, I will raise my concern in script request page.
    Sunday, July 10, 2016 12:51 PM
  • When running the WMI version of CHKDSK you will need to also check the event log on the remote system to see what extended errors might have occurred.  If there are issues with the disk or if it is not the correct type it may give return of 3 (Unknown Error).

    Drive C will not be available for scanning on most systems as the OS will not release its locks.  On W10 systems the system drive always returns code 3.

    You cannot remotely schedule a reboot scan or a "fix". 

    If you change this:
    $VigorousIndexCheck = $true     # performs a vigorous check of the indexes

    to $false it will likely work. Adding any extended scan will fail on the system drive.

    Change this to $true for scheduling a boot scan:

    $OKToRunAtBootup    = $false    # runs now, vs at next bootup


    \_(ツ)_/



    • Edited by jrv Sunday, July 10, 2016 3:51 PM
    Sunday, July 10, 2016 3:42 PM
  • For a code 3 failure on the system drive we get the following event: "Chkdsk was executed in read-only mode on a volume snapshot. "

    Event 26212 (Provider Chkdsk).


    \_(ツ)_/

    Sunday, July 10, 2016 3:54 PM
  • I also notice that this can fail on very large volumes due to WMI exceeding hard coded resource limits.  The answer might be to schedule a reboot scan and let the system do the scan.  I get failures on volumes exceeding 265Gb.


    \_(ツ)_/

    Sunday, July 10, 2016 4:04 PM
  • Thank you.. :) That helps.. I've modified the script as suggested by you but still the issue persists. So to make sure I've logged into the server and ran it and it failed. Is there anyway apart from fetching the event log details as it will be a tedious task since the script will be running for nearly 100 to 200 servers.. :(
    Monday, July 11, 2016 1:11 PM
  • You will find that running ChkDsk remotely on the system drive is not very useful.  I recommend using Group Policy to force a chkdsk on the system drive.

    There is no work around as the WMI limits are hard coded.


    \_(ツ)_/

    • Marked as answer by H_Karthik Monday, July 11, 2016 1:42 PM
    Monday, July 11, 2016 1:26 PM
  • Thank you for the reply :)
    Monday, July 11, 2016 1:44 PM