Defragment Analysis VBS | Local or Remote


Hello,

This script runs a defragment analysis on the system, checking all drives.

######################################### Start Script#########################################

strComputer = “.”

Dim strComputer, objNetwork

Set objNetwork = WScript.CreateObject(“WScript.Network”)

set objWMI = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2”)

set colVols = objWMI.ExecQuery(“Select * from Win32_Volume where DriveType = 3”)

WScript.echo “;” & “Server Name;” & “Value;” & “Volume Name;” & ” Volume size; ” & ” Cluster size; ” & ” Used space; ” & ” Free space; ” & ” Percent free space;” & ” Total fragmentation; ” & ” File fragmentation; ” & ” Free space fragmentation; ” & ” Total fragmented files; ” & ” Total excess fragments; ” & ” Page file size; ” & ” Total excess fragments; ” & ” Total page file fragments; ”

for each objVol in colVols

intRC = objVol.DefragAnalysis(boolDefrag, objRpt)

if intRC = 0 then

if boolDefrag = True Then

WScript.Echo “;” & objNetwork.ComputerName & “; You should defragment this volume;” & objVol.DriveLetter & “;” & objRpt.VolumeSize & “;” & objRpt.ClusterSize & “;” & objRpt.UsedSpace & “;” & objRpt.FreeSpace & “;” & objRpt.FreeSpacePercent &”;” & objRpt.TotalPercentFragmentation & “;”& objRpt.FilePercentFragmentation & “;” & objRpt.FreeSpacePercentFragmentation & “;” & objRpt.TotalFragmentedFiles & “;” & objRpt.TotalExcessFragments & “;” & objRpt.PageFileSize & “;” & objRpt.TotalExcessFragments& “;” & objRpt.TotalPageFileFragments

else

WScript.Echo “;” & objNetwork.ComputerName & “; You do not need to defragment this volume” & “;” & objVol.DriveLetter & “;” & objRpt.VolumeSize & “;” & objRpt.ClusterSize & “;” & objRpt.UsedSpace & “;” & objRpt.FreeSpace & “;” & objRpt.FreeSpacePercent &”;” & objRpt.TotalPercentFragmentation & “;”& objRpt.FilePercentFragmentation & “;” & objRpt.FreeSpacePercentFragmentation & “;” & objRpt.TotalFragmentedFiles & “;” & objRpt.TotalExcessFragments & “;” & objRpt.PageFileSize & “;” & objRpt.TotalExcessFragments& “;” & objRpt.TotalPageFileFragments

end if

else

WScript.Echo “Error during defragmentation analysis: ” & intRC

end if

next

######################################### End Script#########################################

Advertisements

One thought on “Defragment Analysis VBS | Local or Remote

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s