Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Remote Defrag Via Script

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,3361
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Remote Defrag Via Script
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Remote Defrag Via Script - 6/13/2005 11:01:06 PM   
  Dazza

 

Posts: 2
Score: 0
Joined: 6/13/2005
From: United Kingdom
Status: offline
Hi I am very new to scripting in general, but I am looking to run a scheduled remote defragmentation of the system partition (c:) on all workstations within our organisation. Would anyone have a script capable of doing this? Or would you be able to assist me?

Ideally I would like this to run from a centralised server (one of our domain controllers) once a month. I imagine I would also need the script to reference a text file containing a list of all the workstations within our organisation? Is this the case? I also want the script to continue in instances whereby a workstation is offline for whatever reason.

Any help would be greatly appreciated.

Regards,

Darren
 
 
Post #: 1
 
 Re: Remote Defrag Via Script - 6/14/2005 12:04:09 AM   
  mbouchard


Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
How many pc's are you talking about? If the number is hi, running this remotely would not be ideal. Also, do you have a script that will run the defrag on a PC? If you had that in place it would not be too difficult to make it run on a remote PC.

(in reply to Dazza)
 
 
Post #: 2
 
 Re: Remote Defrag Via Script - 6/14/2005 12:09:56 AM   
  Dazza

 

Posts: 2
Score: 0
Joined: 6/13/2005
From: United Kingdom
Status: offline
quote:
Originally posted by mbouchard

How many pc's are you talking about? If the number is hi, running this remotely would not be ideal. Also, do you have a script that will run the defrag on a PC? If you had that in place it would not be too difficult to make it run on a remote PC.



Hi Mike,

It would be approximately 700 workstations, and we plan to run this once a month out of hours (overnight.)

As I have said I am totally new to scripting in all honesty so I don't actually have a script but a simple defrag c: /f command would run the script on the system partition and with the /f would force it even if there isn't enough available disk space.

Could you instruct me on how I could make it run on a remote PC? Would I need a line referencing a .txt file containing all the workstation names?

Thanks in advance for your help

(in reply to Dazza)
 
 
Post #: 3
 
 Re: Remote Defrag Via Script - 6/14/2005 1:30:57 AM   
  mbouchard


Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
You can use a tool from sysinternals to run an exe/Bat/cmd on a remote PC. Look for PSexec which is part of PStools. As too getting the workstations, you have several options.

1) some how export the PC's to a text file then read from this using readall and split. What this will give you is an array that you can loop through. Readline would also work. You might need to manually edit this list to get any PC out that you do not want to run defrag on, i.e. servers etc. Also, you will need to keep updating this text file to make sure any and all changes are noted.

2) Use ADSI to read all PC's into an array. This will allow you to list exceptions that you do not want to defrag. here is a sample on how to do this.

      

3) Use AD, if you have it, to do the same thing as ADSI but depending on how you have AD setup, i.e. servers in their own OU, it would be a bit easier to leave out particular PC's.

That is getting the PC's. Now how do you use it. What I would probably do, if you really want to use a scheduld task from a server, would be to do this.
On the server:
Have a script (we will call it Server.vbs) that includes 1 of the above was to get the PC name. Then use ping to make sure that the PC is online. Report to a text file, database, or whatever you want the success or fail of the ping. If the ping test passes, then call a cmd file on a remote PC using Psexec. Make sure you do not use wait on return and you use the switch for Psexec that does not wait for the remote app. This way the server script will not take too long to run.

Remote CMD
In this cmd file you can either call the defrag or call a script on the local PC. I would go with the latter for reporting purposes.

Remote Script
Set a timer, I would use NOW. Run the defrag with a wait on return, then use datediff to find out how long the defrag ran. You can then report to a text file or a database how long the defrag ran, and if you use the verbose switch you can then read that info and parse it to get any data you want out of the defrag report and write this to where ever you are reporting.


Reporting can make this a more complex script, if you do not care about the reporting then it would be easier to write. What I would do is take this in steps. Start basic, get it working, then add in whatever else you need.

(in reply to Dazza)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Remote Defrag Via Script Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts