time effecient defrag on multiple servers from a txt file

This scripts defrags multiple volumes on multiple servers in the same time using PS background jobs , servers are imported from a txt file of server names

 
 
 
 
 
5 Star
(1)
Add to favorites
Storage
4/12/2010
E-mail Twitter del.icio.us Digg Facebook
  • Completely New To This
    2 Posts | Last post July 29, 2013
    • I'm not a scriptor but I was tasked with taking care of the performance on an SQL Server.  I realized that a few of our servers are over 49% Fragemented.
      
      I tried copying the script and running it in powershell, but it wouldn't run.
      
      How would I go about initiating your powershell script?
      
      thanks for your help
    • I do not know how to run this script, I tried multiple ways and nothing is happening, such as scripname.PS1 and using your method, but no luck.
  • Enhancement
    4 Posts | Last post July 18, 2010
    • Mohamed,
      
      Curious but would it still be possible to not wait for the jobs to complete? Or actually what would be nice if there was a timeframe (maint period) I could put in as a parameter and then if it's not done it will stop defragging but when the timout expires then the script will resume with the remaining servers in the list in addition to the last one it had to cancel. That way the script could possibly be run 24/7.
      
      I guess I am looking for the possibility of something to manage native windows defragmentation for our servers here without being invasive to our user base.
      
      Thanks for all your help. I love the script
    • hi 
      the background jobs are meant to add time effciency to the script , wmi method for defragging is a blocking method , when you invoke defrag by wmi on certian volume on a server , the script blocks and waits for the defrag to finish , then the script continues , that's why i am using the background jobs to be able to hop to a different server running the previous as a background job.
      if you run a defrag forexample on drive C: on server A , you cannot run at the same time defrag D: on server A , you have to wait for defragging C: to finish.
      i agree with you totally on putting a time threshold parameter ,but  unfortunalty as far as i know ,you cannot stop a running defrag using WMI , there is no method to recall the defrag , or even know the % completed,  you'd have to end the process "defrag.exe" remotely and i think this is not good :)
      so i suggest that you begin with a small number of computers as an input to the script , then add more computers to that , so at the end most computers will have a very low fragmentation level and they won't take too much time in execution .
    • HI
      
      I cant run this script on Windows 7 Powershell.
      i set execution policy on remotesigned and unrestricted, but dont receive any action from script. No error, no defrag, nothing.
      
      Can you help.me
      
      Regards
    • hi
      make sure you comment out what you need from the last part of the script which is 
      #--------------------------------------
      #you can run the script this way , to defrag a single server 
      #wmidefrag server1
      #-------------------------------------------
      #you can run the script this way , to defrag multiple computers
      #c:\servers.txt is a text file in the format of a servername per line  
      #get-content c:\servers.txt | Wmidefrag | Tee-object -filepath C:\ds.txt