Jump to content

Recommended Posts

Posted

Hi there,

I am looking for a little help. I have around 35 stations I would like to remote defrag.

There is a useful remote powershell command which allows you to defrag a remote system:

 

Get-WmiObject win32_volume -filter "driveletter='c:'" -ComputerName computer-name-here | Invoke-WmiMethod -Name Defrag

 

This works quite well, but could take a while to do as you would need to manually enter in the computer name each time.

Does anyone have any ideas on how I could make this quicker? Also, would be good if there is a way to see progress or get confirmation that the command went through - I am assuming it is working as I didn't get a red error text reply after hitting return.

 

Defrag.PNG

 

Thanks in advance.

Posted (edited)

Hopefully this will help. Doing this from my phone so can't confirm syntax and commands.

 

Put computer names in an array

$computers = "computer1", "computer2", "computer3"

 

Foreach $a in $computers { get-wmiobject .....}

 

Obviously put all computer names in computers array and complete the command in { } and where you have computer name reference $a

 

Hopefully​ this will help. If not have a Google for "foreach powershell"

 

Don't know if you check if it is complete. Is there a wmi query for this???

Edited by benjie
  • Thanks 1
Posted
Does Win 7+ do this during maintenance?

Yes.

 

www.thewindowsclub.com/disk-defragmenter-windows

 

The Disk Defragmenter runs as a low priority task in the background without affecting the performance of the computer. It runs only when the machine is idle. It uses the Task Scheduler to automatically keep the hard disk defragmented. This automated defragmentation does not affect the performance of the Windows.
  • Thanks 1
Posted

create a folder and put psexec inside. then create a batch file with the below,and double click to run it.

 

Export all pc names from AD open in excel then add the extra bits to it to get the full line.

 

PsExec -s -d \\pcname1 c:\windows\system32\defrag.exe c: -f PsExec -s -d \\pcname2 c:\windows\system32\defrag.exe c: -f PsExec -s -d \\pcname3 c:\windows\system32\defrag.exe c: -f

etc

etc

etc

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...