Guest maxime Posted September 24, 2007 Posted September 24, 2007 Hi Question about server en workstations defragmentation Is there a way to centrally manage disc defrag in a small network with one SBS 2003 server, AD -DC configured and 10 XP SP2 Workstations ? my workaround is to set a scheduling on each workstation to run "defrag.exe c: -f" wich is not the best practice. with this workaround i'm unable to create an overview of each workstationhealthstatus. Can i install a tool that enables me to manage disc cleanup- defrag and disccheck from the active directory for example and give me statusreport ? Thank you in advance Best regards Maxime
Guest Lanwench [MVP - Exchange] Posted September 24, 2007 Posted September 24, 2007 Re: centrally manage defragmenation maxime <maxime@discussions.microsoft.com> wrote: > Hi > > Question about server en workstations defragmentation > > Is there a way to centrally manage disc defrag in a small network > with one SBS 2003 server, AD -DC configured and 10 XP SP2 > Workstations ? > my workaround is to set a scheduling on each workstation to run > "defrag.exe c: -f" > wich is not the best practice. > with this workaround i'm unable to create an overview of each > workstationhealthstatus. > > Can i install a tool that enables me to manage disc cleanup- defrag > and disccheck from the active directory for example and give me > statusreport ? > > Thank you in advance > > Best regards > Maxime How often are you finding you need to do defrags, honestly? I do them on an as-needed basis, myself. There's not much you can do with the built-in defrag tool, and certainly nothing you can centrally manage. If you find you need more, invest in something better, like Raxco's PerfectDisk or Executive Software's DiskKeeper.
Guest Mathieu CHATEAU Posted September 24, 2007 Posted September 24, 2007 Re: centrally manage defragmenation Hello, I use this one which create txt report at the root of all drives. '========================================================================== ' 'AUTHOR: Ed Wilson , msft, 7/5/2006 ' NAME: <DefragAllDrivesParam.vbs> ' ' COMMENT: <Use the win32_Volume class to defrag hard drives> '1. This class is a new class for Windows 2003 Server and Windows Vista. This '2. script WILL NOT work on previous versions of the Windows operating system. '========================================================================== Option Explicit On Error Resume Next dim strComputer dim wmiNS dim wmiQuery dim objWMIService dim colItems dim objItem Dim colNamedArguments 'WshNamed object Dim strAction subCheckCscript 'check to see if running in cscript Set colNamedArguments = WScript.Arguments.Named strAction = colNamedArguments("a") subCheckArguments strComputer = "." wmiNS = "\root\cimv2" wmiQuery = "Select name from win32_volume where driveType = '3'" Set objWMIService = GetObject("winmgmts:\\" & strComputer & wmiNS) If strAction = "d" Then Set colItems = objWMIService.ExecQuery(wmiQuery) For Each objItem In colItems intRTN =objItem.defrag() subERR Next Else WScript.Echo "To defrag your drive try: cscript " & WScript.ScriptName & "/a:d" WScript.Echo "For help try: cscript " & WScript.ScriptName & " /?" WScript.Quit End If Sub subCheckCscript If UCase(Right(Wscript.FullName, 11)) = "WSCRIPT.EXE" Then Wscript.Echo "This script must be run under CScript" WScript.Quit End If end Sub Sub subCheckArguments If colNamedArguments.Count < 2 Then If colNamedArguments.Exists("?") Then WScript.Echo "Uses win32_Volume class to defrag the hard drive" _ & VbCrLf & "This script requires the /d:a argument to perform the defrag. " _ & VbCrLf & "Once the defrag begins, it can take a long time to complete" _ & VbCrLf & "Do not stop the defrag process as it can leave your drive in "_ & VbCrLf & "an unsupported state. This script will defrag all the drives"_ & VbCrLf & "Try this:cscript DefragAllDrives.vbs /a:d(efrag)" _ & VbCrLf & "Example: cscript " & WScript.ScriptName & " /a:d" _ & VbCrLf & vbTab & " Defrags all drives on local system" WScript.Quit End If End If If colNamedArguments.Count = 0 Then Exit Sub End If End Sub sub subERR If intRTN <> 0 Then WScript.echo "An error occurred trying to defrag drive " & objItem.name & _ "The error was: " &_ vbnewline & Err.Number & vbtab & Err.Description Else WScript.echo "Defrag successful on " & objItem.name End If End Sub -- Cordialement, Mathieu CHATEAU http://lordoftheping.blogspot.com "maxime" <maxime@discussions.microsoft.com> wrote in message news:21D12085-9C74-4566-954F-CFE11DBAB7BF@microsoft.com... > Hi > > Question about server en workstations defragmentation > > Is there a way to centrally manage disc defrag in a small network with > one > SBS 2003 server, AD -DC configured and 10 XP SP2 Workstations ? > my workaround is to set a scheduling on each workstation to run > "defrag.exe > c: -f" > wich is not the best practice. > with this workaround i'm unable to create an overview of each > workstationhealthstatus. > > Can i install a tool that enables me to manage disc cleanup- defrag and > disccheck from the active directory for example and give me statusreport ? > > Thank you in advance > > Best regards > Maxime
Guest Lanwench [MVP - Exchange] Posted September 24, 2007 Posted September 24, 2007 Re: centrally manage defragmenation Mathieu CHATEAU <gollum123@free.fr> wrote: > Hello, > > I use this one which create txt report at the root of all drives. This looks lovely, but she's on SBS 2003 with WinXP clients. :( > > > > '========================================================================== > ' > 'AUTHOR: Ed Wilson , msft, 7/5/2006 > ' NAME: <DefragAllDrivesParam.vbs> > ' > ' COMMENT: <Use the win32_Volume class to defrag hard drives> > '1. This class is a new class for Windows 2003 Server and Windows > Vista. This > '2. script WILL NOT work on previous versions of the Windows operating > system. > '========================================================================== > Option Explicit > On Error Resume Next > dim strComputer > dim wmiNS > dim wmiQuery > dim objWMIService > dim colItems > dim objItem > Dim colNamedArguments 'WshNamed object > Dim strAction > subCheckCscript 'check to see if running in cscript > > Set colNamedArguments = WScript.Arguments.Named > strAction = colNamedArguments("a") > subCheckArguments > > strComputer = "." > wmiNS = "\root\cimv2" > wmiQuery = "Select name from win32_volume where driveType = '3'" > Set objWMIService = GetObject("winmgmts:\\" & strComputer & wmiNS) > > > If strAction = "d" Then > Set colItems = objWMIService.ExecQuery(wmiQuery) > For Each objItem In colItems > intRTN =objItem.defrag() > subERR > Next > Else > WScript.Echo "To defrag your drive try: cscript " & > WScript.ScriptName & "/a:d" > WScript.Echo "For help try: cscript " & WScript.ScriptName & " > /?" WScript.Quit > End If > > > Sub subCheckCscript > If UCase(Right(Wscript.FullName, 11)) = "WSCRIPT.EXE" Then > Wscript.Echo "This script must be run under CScript" > WScript.Quit > End If > end Sub > > Sub subCheckArguments > > If colNamedArguments.Count < 2 Then > If colNamedArguments.Exists("?") Then > WScript.Echo "Uses win32_Volume class to defrag the hard drive" _ > & VbCrLf & "This script requires the /d:a argument to perform the > defrag. " _ > & VbCrLf & "Once the defrag begins, it can take a long time to > complete" _ & VbCrLf & "Do not stop the defrag process as it can > leave your drive in "_ & VbCrLf & "an unsupported state. This script > will defrag all the drives"_ & VbCrLf & "Try this:cscript > DefragAllDrives.vbs /a:d(efrag)" _ & VbCrLf & "Example: cscript " & > WScript.ScriptName & " /a:d" _ & VbCrLf & vbTab & " Defrags all > drives on local system" WScript.Quit > End If > End If > If colNamedArguments.Count = 0 Then > Exit Sub > End If > End Sub > > > sub subERR > If intRTN <> 0 Then > WScript.echo "An error occurred trying to defrag drive " & > objItem.name & _ "The error was: " &_ > vbnewline & Err.Number & vbtab & Err.Description > Else > WScript.echo "Defrag successful on " & objItem.name > End If > End Sub > > > > "maxime" <maxime@discussions.microsoft.com> wrote in message > news:21D12085-9C74-4566-954F-CFE11DBAB7BF@microsoft.com... >> Hi >> >> Question about server en workstations defragmentation >> >> Is there a way to centrally manage disc defrag in a small network with >> one >> SBS 2003 server, AD -DC configured and 10 XP SP2 Workstations ? >> my workaround is to set a scheduling on each workstation to run >> "defrag.exe >> c: -f" >> wich is not the best practice. >> with this workaround i'm unable to create an overview of each >> workstationhealthstatus. >> >> Can i install a tool that enables me to manage disc cleanup- defrag >> and disccheck from the active directory for example and give me >> statusreport ? Thank you in advance >> >> Best regards >> Maxime
Guest Mathieu CHATEAU Posted September 24, 2007 Posted September 24, 2007 Re: centrally manage defragmenation You are right, i didn't post the good one... The previous store the report as text anyway This one works on XP & 2003 and generate a txt report 'defrag_all2.vbs 'Defrags all hard disks - Can be run as a Scheduled Task 'Modified to create an error log and display it '© Doug Knox - 4/13/2002 Option Explicit Dim WshShell, fso, d, dc, ErrStr(), Return, X, A(), MyFile, I, MyBox, Drive Set WshShell = WScript.CreateObject("WScript.Shell") Set fso = CreateObject("Scripting.FileSystemObject") X = 0 Set dc = fso.Drives For Each d in DC If d.DriveType = 2 Then X = X + 1 'Determine drive letter of first fixed disk 'This is the drive that the error report will be placed on If X = 1 Then Drive = d End If End If Next ReDim A(X) ReDim ErrStr(X) X = 0 For Each d in dc If d.DriveType = 2 Then X = X + 1 Return = WshShell.Run("defrag " & d & " -f", 1, TRUE) 'Determine the Error code returned by Defrag for the current drive and save it If return = 0 then ErrStr(x) = ErrStr(x) & "Drive " & d & " Defrag completed successfully" & vbCRLF elseif return = 1 then ErrStr(x) = ErrStr(x) & "Drive " & d & " Defrag aborted with error level " & return & " (defrag was cancelled manually) " & vbCRLF elseif return = 2 then ErrStr(x) = ErrStr(x) & "Drive " & d & " Defrag aborted with error level " & return & " (there was a command line error. Check your command line for valid switches and drives)" & vbCRLF elseif return = 3 then ErrStr(x) = ErrStr(x) & "Drive " & d & " Defrag aborted with error level " & return & " (there was an unknown error)" & vbCRLF elseif return = 4 then ErrStr(x) = ErrStr(x) & "Drive " & d & " Defrag aborted with error level " & return & " (defrag could not run due to insufficient memory resources)" & vbCRLF 'errorlevel 5 is not currently used elseif return = 5 then ErrStr(x) = ErrStr(x) & "Drive " & d & " Defrag aborted with error level " & return & " (general error)" & vbCRLF elseif return = 6 then ErrStr(x) = ErrStr(x) & "Drive " & d & " Defrag aborted with error level " & return & "(System error: either the account used to run defrag is not an administrator, there is a problem loading the resource DLL, or a defrag engine could not be accessed. Check for proper user permissions and run Sfc.exe to validate system files)" & vbCRLF elseif return = 7 then ErrStr(x) = ErrStr(x) & "Drive " & d & " Defrag aborted with error level " & return & " (There is not enough free space on the drive. Defrag needs 15% free space to run on a volume)" & vbCRLF else ErrStr(x) = ErrStr(x) & "Drive " & d & " Defrag aborted with an unknown error level: " & return & vbCRLF end if End If Next 'Create the Error Report in the root of the first fixed disk. Set MyFile = fso.OpenTextFile(Drive & "\defragreport.txt", 2, True) MyFile.WriteLine(Date) & vbCRLF MyFile.WriteLine(Time) & vbCRLF For I = 1 to X MyFile.WriteLine(ErrStr(I)) Next MyFile.Close Set WshShell = Nothing Set fso = Nothing -- Cordialement, Mathieu CHATEAU http://lordoftheping.blogspot.com "Lanwench [MVP - Exchange]" <lanwench@heybuddy.donotsendme.unsolicitedmailatyahoo.com> wrote in message news:%23LxcZau$HHA.3956@TK2MSFTNGP03.phx.gbl... > Mathieu CHATEAU <gollum123@free.fr> wrote: >> Hello, >> >> I use this one which create txt report at the root of all drives. > > This looks lovely, but she's on SBS 2003 with WinXP clients. :( >> >> >> >> '========================================================================== >> ' >> 'AUTHOR: Ed Wilson , msft, 7/5/2006 >> ' NAME: <DefragAllDrivesParam.vbs> >> ' >> ' COMMENT: <Use the win32_Volume class to defrag hard drives> >> '1. This class is a new class for Windows 2003 Server and Windows >> Vista. This >> '2. script WILL NOT work on previous versions of the Windows operating >> system. >> '========================================================================== >> Option Explicit >> On Error Resume Next >> dim strComputer >> dim wmiNS >> dim wmiQuery >> dim objWMIService >> dim colItems >> dim objItem >> Dim colNamedArguments 'WshNamed object >> Dim strAction >> subCheckCscript 'check to see if running in cscript >> >> Set colNamedArguments = WScript.Arguments.Named >> strAction = colNamedArguments("a") >> subCheckArguments >> >> strComputer = "." >> wmiNS = "\root\cimv2" >> wmiQuery = "Select name from win32_volume where driveType = '3'" >> Set objWMIService = GetObject("winmgmts:\\" & strComputer & wmiNS) >> >> >> If strAction = "d" Then >> Set colItems = objWMIService.ExecQuery(wmiQuery) >> For Each objItem In colItems >> intRTN =objItem.defrag() >> subERR >> Next >> Else >> WScript.Echo "To defrag your drive try: cscript " & >> WScript.ScriptName & "/a:d" >> WScript.Echo "For help try: cscript " & WScript.ScriptName & " >> /?" WScript.Quit >> End If >> >> >> Sub subCheckCscript >> If UCase(Right(Wscript.FullName, 11)) = "WSCRIPT.EXE" Then >> Wscript.Echo "This script must be run under CScript" >> WScript.Quit >> End If >> end Sub >> >> Sub subCheckArguments >> >> If colNamedArguments.Count < 2 Then >> If colNamedArguments.Exists("?") Then >> WScript.Echo "Uses win32_Volume class to defrag the hard drive" _ >> & VbCrLf & "This script requires the /d:a argument to perform the >> defrag. " _ >> & VbCrLf & "Once the defrag begins, it can take a long time to >> complete" _ & VbCrLf & "Do not stop the defrag process as it can >> leave your drive in "_ & VbCrLf & "an unsupported state. This script >> will defrag all the drives"_ & VbCrLf & "Try this:cscript >> DefragAllDrives.vbs /a:d(efrag)" _ & VbCrLf & "Example: cscript " & >> WScript.ScriptName & " /a:d" _ & VbCrLf & vbTab & " Defrags all >> drives on local system" WScript.Quit >> End If >> End If >> If colNamedArguments.Count = 0 Then >> Exit Sub >> End If >> End Sub >> >> >> sub subERR >> If intRTN <> 0 Then >> WScript.echo "An error occurred trying to defrag drive " & >> objItem.name & _ "The error was: " &_ >> vbnewline & Err.Number & vbtab & Err.Description >> Else >> WScript.echo "Defrag successful on " & objItem.name >> End If >> End Sub >> >> >> >> "maxime" <maxime@discussions.microsoft.com> wrote in message >> news:21D12085-9C74-4566-954F-CFE11DBAB7BF@microsoft.com... >>> Hi >>> >>> Question about server en workstations defragmentation >>> >>> Is there a way to centrally manage disc defrag in a small network with >>> one >>> SBS 2003 server, AD -DC configured and 10 XP SP2 Workstations ? >>> my workaround is to set a scheduling on each workstation to run >>> "defrag.exe >>> c: -f" >>> wich is not the best practice. >>> with this workaround i'm unable to create an overview of each >>> workstationhealthstatus. >>> >>> Can i install a tool that enables me to manage disc cleanup- defrag >>> and disccheck from the active directory for example and give me >>> statusreport ? Thank you in advance >>> >>> Best regards >>> Maxime > > >
Guest maxime Posted September 25, 2007 Posted September 25, 2007 Re: centrally manage defragmenation Tnnx for your post i ll keep your recommendations in mind. best regards maxime "Mathieu CHATEAU" wrote: > You are right, i didn't post the good one... > The previous store the report as text anyway > > This one works on XP & 2003 and generate a txt report > > > 'defrag_all2.vbs > 'Defrags all hard disks - Can be run as a Scheduled Task > 'Modified to create an error log and display it > '© Doug Knox - 4/13/2002 > > Option Explicit > > Dim WshShell, fso, d, dc, ErrStr(), Return, X, A(), MyFile, I, MyBox, Drive > > Set WshShell = WScript.CreateObject("WScript.Shell") > Set fso = CreateObject("Scripting.FileSystemObject") > X = 0 > > Set dc = fso.Drives > For Each d in DC > If d.DriveType = 2 Then > X = X + 1 > > 'Determine drive letter of first fixed disk > 'This is the drive that the error report will be placed on > If X = 1 Then > Drive = d > End If > End If > Next > > ReDim A(X) > ReDim ErrStr(X) > > X = 0 > For Each d in dc > If d.DriveType = 2 Then > X = X + 1 > Return = WshShell.Run("defrag " & d & " -f", 1, TRUE) > > 'Determine the Error code returned by Defrag for the current drive and save > it > If return = 0 then > ErrStr(x) = ErrStr(x) & "Drive " & d & " Defrag completed successfully" & > vbCRLF > elseif return = 1 then > ErrStr(x) = ErrStr(x) & "Drive " & d & " Defrag aborted with error level > " & return & " (defrag was cancelled manually) " & vbCRLF > elseif return = 2 then > ErrStr(x) = ErrStr(x) & "Drive " & d & " Defrag aborted with error level > " & return & " (there was a command line error. Check your command line for > valid switches and drives)" & vbCRLF > elseif return = 3 then > ErrStr(x) = ErrStr(x) & "Drive " & d & " Defrag aborted with error level > " & return & " (there was an unknown error)" & vbCRLF > elseif return = 4 then > ErrStr(x) = ErrStr(x) & "Drive " & d & " Defrag aborted with error level > " & return & " (defrag could not run due to insufficient memory resources)" > & vbCRLF > 'errorlevel 5 is not currently used > elseif return = 5 then > ErrStr(x) = ErrStr(x) & "Drive " & d & " Defrag aborted with error level > " & return & " (general error)" & vbCRLF > elseif return = 6 then > ErrStr(x) = ErrStr(x) & "Drive " & d & " Defrag aborted with error level > " & return & "(System error: either the account used to run defrag is not an > administrator, there is a problem loading the resource DLL, or a defrag > engine could not be accessed. Check for proper user permissions and run > Sfc.exe to validate system files)" & vbCRLF > elseif return = 7 then > ErrStr(x) = ErrStr(x) & "Drive " & d & " Defrag aborted with error level > " & return & " (There is not enough free space on the drive. Defrag needs > 15% free space to run on a volume)" & vbCRLF > else > ErrStr(x) = ErrStr(x) & "Drive " & d & " Defrag aborted with an unknown > error level: " & return & vbCRLF > end if > > End If > Next > > 'Create the Error Report in the root of the first fixed disk. > Set MyFile = fso.OpenTextFile(Drive & "\defragreport.txt", 2, True) > MyFile.WriteLine(Date) & vbCRLF > MyFile.WriteLine(Time) & vbCRLF > For I = 1 to X > MyFile.WriteLine(ErrStr(I)) > Next > MyFile.Close > > Set WshShell = Nothing > Set fso = Nothing > > -- > Cordialement, > Mathieu CHATEAU > http://lordoftheping.blogspot.com > > > "Lanwench [MVP - Exchange]" > <lanwench@heybuddy.donotsendme.unsolicitedmailatyahoo.com> wrote in message > news:%23LxcZau$HHA.3956@TK2MSFTNGP03.phx.gbl... > > Mathieu CHATEAU <gollum123@free.fr> wrote: > >> Hello, > >> > >> I use this one which create txt report at the root of all drives. > > > > This looks lovely, but she's on SBS 2003 with WinXP clients. :( > >> > >> > >> > >> '========================================================================== > >> ' > >> 'AUTHOR: Ed Wilson , msft, 7/5/2006 > >> ' NAME: <DefragAllDrivesParam.vbs> > >> ' > >> ' COMMENT: <Use the win32_Volume class to defrag hard drives> > >> '1. This class is a new class for Windows 2003 Server and Windows > >> Vista. This > >> '2. script WILL NOT work on previous versions of the Windows operating > >> system. > >> '========================================================================== > >> Option Explicit > >> On Error Resume Next > >> dim strComputer > >> dim wmiNS > >> dim wmiQuery > >> dim objWMIService > >> dim colItems > >> dim objItem > >> Dim colNamedArguments 'WshNamed object > >> Dim strAction > >> subCheckCscript 'check to see if running in cscript > >> > >> Set colNamedArguments = WScript.Arguments.Named > >> strAction = colNamedArguments("a") > >> subCheckArguments > >> > >> strComputer = "." > >> wmiNS = "\root\cimv2" > >> wmiQuery = "Select name from win32_volume where driveType = '3'" > >> Set objWMIService = GetObject("winmgmts:\\" & strComputer & wmiNS) > >> > >> > >> If strAction = "d" Then > >> Set colItems = objWMIService.ExecQuery(wmiQuery) > >> For Each objItem In colItems > >> intRTN =objItem.defrag() > >> subERR > >> Next > >> Else > >> WScript.Echo "To defrag your drive try: cscript " & > >> WScript.ScriptName & "/a:d" > >> WScript.Echo "For help try: cscript " & WScript.ScriptName & " > >> /?" WScript.Quit > >> End If > >> > >> > >> Sub subCheckCscript > >> If UCase(Right(Wscript.FullName, 11)) = "WSCRIPT.EXE" Then > >> Wscript.Echo "This script must be run under CScript" > >> WScript.Quit > >> End If > >> end Sub > >> > >> Sub subCheckArguments > >> > >> If colNamedArguments.Count < 2 Then > >> If colNamedArguments.Exists("?") Then > >> WScript.Echo "Uses win32_Volume class to defrag the hard drive" _ > >> & VbCrLf & "This script requires the /d:a argument to perform the > >> defrag. " _ > >> & VbCrLf & "Once the defrag begins, it can take a long time to > >> complete" _ & VbCrLf & "Do not stop the defrag process as it can > >> leave your drive in "_ & VbCrLf & "an unsupported state. This script > >> will defrag all the drives"_ & VbCrLf & "Try this:cscript > >> DefragAllDrives.vbs /a:d(efrag)" _ & VbCrLf & "Example: cscript " & > >> WScript.ScriptName & " /a:d" _ & VbCrLf & vbTab & " Defrags all > >> drives on local system" WScript.Quit > >> End If > >> End If > >> If colNamedArguments.Count = 0 Then > >> Exit Sub > >> End If > >> End Sub > >> > >> > >> sub subERR > >> If intRTN <> 0 Then > >> WScript.echo "An error occurred trying to defrag drive " & > >> objItem.name & _ "The error was: " &_ > >> vbnewline & Err.Number & vbtab & Err.Description > >> Else > >> WScript.echo "Defrag successful on " & objItem.name > >> End If > >> End Sub > >> > >> > >> > >> "maxime" <maxime@discussions.microsoft.com> wrote in message > >> news:21D12085-9C74-4566-954F-CFE11DBAB7BF@microsoft.com... > >>> Hi > >>> > >>> Question about server en workstations defragmentation > >>> > >>> Is there a way to centrally manage disc defrag in a small network with > >>> one > >>> SBS 2003 server, AD -DC configured and 10 XP SP2 Workstations ? > >>> my workaround is to set a scheduling on each workstation to run > >>> "defrag.exe > >>> c: -f" > >>> wich is not the best practice. > >>> with this workaround i'm unable to create an overview of each > >>> workstationhealthstatus. > >>> > >>> Can i install a tool that enables me to manage disc cleanup- defrag > >>> and disccheck from the active directory for example and give me > >>> statusreport ? Thank you in advance > >>> > >>> Best regards > >>> Maxime > > > > > > > >
Guest Lanwench [MVP - Exchange] Posted September 25, 2007 Posted September 25, 2007 Re: centrally manage defragmenation Mathieu CHATEAU <gollum123@free.fr> wrote: > You are right, i didn't post the good one... > The previous store the report as text anyway > > This one works on XP & 2003 and generate a txt report Very nice - Doug Knox strikes again! Merci, Mathieu. > > > 'defrag_all2.vbs > 'Defrags all hard disks - Can be run as a Scheduled Task > 'Modified to create an error log and display it > '© Doug Knox - 4/13/2002 > > Option Explicit > > Dim WshShell, fso, d, dc, ErrStr(), Return, X, A(), MyFile, I, MyBox, > Drive > Set WshShell = WScript.CreateObject("WScript.Shell") > Set fso = CreateObject("Scripting.FileSystemObject") > X = 0 > > Set dc = fso.Drives > For Each d in DC > If d.DriveType = 2 Then > X = X + 1 > > 'Determine drive letter of first fixed disk > 'This is the drive that the error report will be placed on > If X = 1 Then > Drive = d > End If > End If > Next > > ReDim A(X) > ReDim ErrStr(X) > > X = 0 > For Each d in dc > If d.DriveType = 2 Then > X = X + 1 > Return = WshShell.Run("defrag " & d & " -f", 1, TRUE) > > 'Determine the Error code returned by Defrag for the current drive > and save it > If return = 0 then > ErrStr(x) = ErrStr(x) & "Drive " & d & " Defrag completed > successfully" & vbCRLF > elseif return = 1 then > ErrStr(x) = ErrStr(x) & "Drive " & d & " Defrag aborted with error > level " & return & " (defrag was cancelled manually) " & vbCRLF > elseif return = 2 then > ErrStr(x) = ErrStr(x) & "Drive " & d & " Defrag aborted with error > level " & return & " (there was a command line error. Check your > command line for valid switches and drives)" & vbCRLF > elseif return = 3 then > ErrStr(x) = ErrStr(x) & "Drive " & d & " Defrag aborted with error > level " & return & " (there was an unknown error)" & vbCRLF > elseif return = 4 then > ErrStr(x) = ErrStr(x) & "Drive " & d & " Defrag aborted with error > level " & return & " (defrag could not run due to insufficient memory > resources)" & vbCRLF > 'errorlevel 5 is not currently used > elseif return = 5 then > ErrStr(x) = ErrStr(x) & "Drive " & d & " Defrag aborted with error > level " & return & " (general error)" & vbCRLF > elseif return = 6 then > ErrStr(x) = ErrStr(x) & "Drive " & d & " Defrag aborted with error > level " & return & "(System error: either the account used to run > defrag is not an administrator, there is a problem loading the > resource DLL, or a defrag engine could not be accessed. Check for > proper user permissions and run Sfc.exe to validate system files)" & > vbCRLF elseif return = 7 then > ErrStr(x) = ErrStr(x) & "Drive " & d & " Defrag aborted with error > level " & return & " (There is not enough free space on the drive. > Defrag needs 15% free space to run on a volume)" & vbCRLF > else > ErrStr(x) = ErrStr(x) & "Drive " & d & " Defrag aborted with an > unknown error level: " & return & vbCRLF > end if > > End If > Next > > 'Create the Error Report in the root of the first fixed disk. > Set MyFile = fso.OpenTextFile(Drive & "\defragreport.txt", 2, True) > MyFile.WriteLine(Date) & vbCRLF > MyFile.WriteLine(Time) & vbCRLF > For I = 1 to X > MyFile.WriteLine(ErrStr(I)) > Next > MyFile.Close > > Set WshShell = Nothing > Set fso = Nothing > > > "Lanwench [MVP - Exchange]" > <lanwench@heybuddy.donotsendme.unsolicitedmailatyahoo.com> wrote in > message news:%23LxcZau$HHA.3956@TK2MSFTNGP03.phx.gbl... >> Mathieu CHATEAU <gollum123@free.fr> wrote: >>> Hello, >>> >>> I use this one which create txt report at the root of all drives. >> >> This looks lovely, but she's on SBS 2003 with WinXP clients. :( >>> >>> >>> >>> '========================================================================== >>> ' >>> 'AUTHOR: Ed Wilson , msft, 7/5/2006 >>> ' NAME: <DefragAllDrivesParam.vbs> >>> ' >>> ' COMMENT: <Use the win32_Volume class to defrag hard drives> >>> '1. This class is a new class for Windows 2003 Server and Windows >>> Vista. This >>> '2. script WILL NOT work on previous versions of the Windows >>> operating system. >>> '========================================================================== >>> Option Explicit >>> On Error Resume Next >>> dim strComputer >>> dim wmiNS >>> dim wmiQuery >>> dim objWMIService >>> dim colItems >>> dim objItem >>> Dim colNamedArguments 'WshNamed object >>> Dim strAction >>> subCheckCscript 'check to see if running in cscript >>> >>> Set colNamedArguments = WScript.Arguments.Named >>> strAction = colNamedArguments("a") >>> subCheckArguments >>> >>> strComputer = "." >>> wmiNS = "\root\cimv2" >>> wmiQuery = "Select name from win32_volume where driveType = '3'" >>> Set objWMIService = GetObject("winmgmts:\\" & strComputer & wmiNS) >>> >>> >>> If strAction = "d" Then >>> Set colItems = objWMIService.ExecQuery(wmiQuery) >>> For Each objItem In colItems >>> intRTN =objItem.defrag() >>> subERR >>> Next >>> Else >>> WScript.Echo "To defrag your drive try: cscript " & >>> WScript.ScriptName & "/a:d" >>> WScript.Echo "For help try: cscript " & WScript.ScriptName & " >>> /?" WScript.Quit >>> End If >>> >>> >>> Sub subCheckCscript >>> If UCase(Right(Wscript.FullName, 11)) = "WSCRIPT.EXE" Then >>> Wscript.Echo "This script must be run under CScript" >>> WScript.Quit >>> End If >>> end Sub >>> >>> Sub subCheckArguments >>> >>> If colNamedArguments.Count < 2 Then >>> If colNamedArguments.Exists("?") Then >>> WScript.Echo "Uses win32_Volume class to defrag the hard drive" _ >>> & VbCrLf & "This script requires the /d:a argument to perform the >>> defrag. " _ >>> & VbCrLf & "Once the defrag begins, it can take a long time to >>> complete" _ & VbCrLf & "Do not stop the defrag process as it can >>> leave your drive in "_ & VbCrLf & "an unsupported state. This script >>> will defrag all the drives"_ & VbCrLf & "Try this:cscript >>> DefragAllDrives.vbs /a:d(efrag)" _ & VbCrLf & "Example: cscript " & >>> WScript.ScriptName & " /a:d" _ & VbCrLf & vbTab & " Defrags all >>> drives on local system" WScript.Quit >>> End If >>> End If >>> If colNamedArguments.Count = 0 Then >>> Exit Sub >>> End If >>> End Sub >>> >>> >>> sub subERR >>> If intRTN <> 0 Then >>> WScript.echo "An error occurred trying to defrag drive " & >>> objItem.name & _ "The error was: " &_ >>> vbnewline & Err.Number & vbtab & Err.Description >>> Else >>> WScript.echo "Defrag successful on " & objItem.name >>> End If >>> End Sub >>> >>> >>> >>> "maxime" <maxime@discussions.microsoft.com> wrote in message >>> news:21D12085-9C74-4566-954F-CFE11DBAB7BF@microsoft.com... >>>> Hi >>>> >>>> Question about server en workstations defragmentation >>>> >>>> Is there a way to centrally manage disc defrag in a small network >>>> with one >>>> SBS 2003 server, AD -DC configured and 10 XP SP2 Workstations ? >>>> my workaround is to set a scheduling on each workstation to run >>>> "defrag.exe >>>> c: -f" >>>> wich is not the best practice. >>>> with this workaround i'm unable to create an overview of each >>>> workstationhealthstatus. >>>> >>>> Can i install a tool that enables me to manage disc cleanup- defrag >>>> and disccheck from the active directory for example and give me >>>> statusreport ? Thank you in advance >>>> >>>> Best regards >>>> Maxime
Aevin Posted September 26, 2007 Posted September 26, 2007 Re: centrally manage defragmenation Hi my workaround is to set a scheduling on each workstation to run "defrag.exe c: -f" wich is not the best practice. Yeah, scheduling or manually defragging can be a headache at times, waiting to schedule for a window (pun unintended) of opportunity when server activity is low, you are around to monitor it etc etc. Scheduled defragging is quite outdated and inefficient IMHO, especially when automatic defragmentation (for servers + workstations) is becoming the norm. Automatic ensures that you can let the defragger run in the background, and whenever it gets a chance to do so it will defrag, thereby keeping fragmentation low continuously instead of only for a short time period of the defrag interval.
Recommended Posts