isDirtyBitSet SVRNAME Examines the remote system and returns a true or false if the chkdsk /f flag was set...

PowerShell
Edit|Remove

<# 
 .Synopsis
  Examines a server to determine if the chkdsk "dirty bit" is set or not.

 .Description
  Examines the registry to see if the dirty bit is set.  If not it will run 
  chkntfs locally to verify that it is not set and returns a true or false

 .Parameter serverName
  The Server you want to check the Dirty Bit on.

 .Example
   isDirtyBitSet myserver
#>
function isDirtyBitSet () {
    param([string]$serverName)
    
    if (($serverName -eq "") -or $serverName -eq $null) {
        write-host "INPUT ERROR:  serverName value can not be blank" -foregroundcolor RED
        return
    } else {
        if (!(Test-Server $serverName)) {
            write-host "INPUT ERROR:  $serverName DOES NOT EXIST" -foregroundcolor RED
            return
        }
    }
    
    
    $regResult=$false
    
    #If the registry reports false... we MUST be sure... so run chkntfs locally and parse the results
    if (!($regResult)) { 

        #we need to be extra sure, so if it's reporting false... let's do a second check...
        Run-RemoteCmdwResults $serverName "chkntfs c:" "c:\temp\chkntfs.out"
        if (test-path "c:\temp\chkntfs.out") { 
                #Write-Host "Successfully collected SrvInfo!" -foregroundcolor GREEN
                [string]$cout = Get-Content "c:\temp\chkntfs.out"
                Write-Host $cout -foregroundcolor DARKCYAN
                #remove-item "c:\temp\chkntfs.out"
                #$regResult = ($cout.tostring().contains("is not dirty"))
                if (($cout.contains("run on next reboot")) -or ($cout.contains("is dirty"))) {
                    $regResult = $true
                }
        } else { 
            Write-Host "Alternate Method Failed to Detect, Please Check Manually!" -foregroundcolor RED 
            $regResult = "Failed"
        }
    }    

	return $regResult
    
}
#export-modulemember -function isDirtyBitSet










function Test-Server
{
    param([string]$computername)
    
    if (($computername -eq "") -or $computername -eq $null) {
        #write-host "INPUT ERROR:  computername value can not be blank" -foregroundcolor RED
        return $false
    }
    
    trap [Exception] { 
	$err1 = $("TRAPPED: " + $_.Exception.GetType().FullName); 
        $err2 = $("TRAPPED: " + $_.Exception.Message); 
	
	#write-host "Error while pinging" -foregroundcolor RED
	return $false
        #continue; 
    }

	$ip=$computername

	if ($ip -ne "") {

		#second ping the server to see if it is even available... 
		$ping = new-object System.Net.NetworkInformation.Ping
		$rslt = $ping.send($ip)
		if ($rslt.status.tostring() –eq “Success”) {

			#Check the admin share to see if it is accessable...
			if ($computername -ne "")
			{
				$IsServerThere=test-path \\$computername\c$
				return $IsServerThere
			}
			else
			{
				#write-host “Unable to access Admin Share” -foregroundcolor RED
				return $false
			}
		}
		else 
		{
			#write-host “Ping Failed” -foregroundcolor RED
			return $false
		}
	}
	else 
	{
		#write-host “IP Resolve Failed” -foregroundcolor RED
		return $false
	}
}