Sabtu, 03 September 2016

PowerShell v2 Win32 Volume Methods Defrag

This morning I saw some chatter about using WMI to get defrag information.  Curious about the method I found this page on MSDN outlining the various methods on the Win32_Volume class:
Win32_Volume Methods 
And, more specifically, I found this page for the Defrag method itself:
Defrag method of the Win32_Volume Class
When I looked at the arguments I only saw one parameter that took input: Force.
uint32 Defrag(
[in]    boolean Force,
[out]   object DefragAnalysis
);
The Force parameter required a Boolean ($true or $false) to indicate whether defragmenting of the volume would occur even if free space is low.  The default is false.  To use this on a specific volume use this syntax:
Start-Job -ScriptBlock { (Get-WmiObject -Class Win32_Volume -Filter "DriveLetter=C:").Defrag($true) }
Now, the Job cmdlet is not necessary, but, I would rather do this to prevent issue with single-threading (and locking up) my shell.

lamsim

About lamsim

Author Description here.. Nulla sagittis convallis. Curabitur consequat. Quisque metus enim, venenatis fermentum, mollis in, porta et, nibh. Duis vulputate elit in elit. Mauris dictum libero id justo.

Subscribe to this Blog via Email :