Monday, August 23, 2010

Remotely defrag Windows 2003 and 2008

I needed to defrag some harddisks the other day and started logging into them to start the defrag process. I didnt like the idea of my credentials being open on a console when I wasnt there, but I didnt know of any better process (outside of purchasing 3rd party products).

A little googling turned up the following. Its a poweshell script that analyzes disk fragementation, and then launches defrag on the remote system. Original source:

$servers="SERVER1", "SERVER2"

foreach( $server in $servers){
Write-Host ""
$v=(gwmi win32_volume -computer $server)
"CURRENT SERVER: {0} " -f $server
"NUMBER VOLUMES: {0} " -f $v.length
foreach( $volume in $v){
Write-Host ""
write-host "Analyzing fragmentation on" ($volume.DriveLetter) "..."
if ($frag -gt "10") {
write-host "Drive" ($volume.DriveLetter) "is currently" $frag "% fragmented." -foreground RED
write-host "Starting remote defrag..."
else {
Write-host "Drive" ($volume.DriveLetter) "is not fragmented" -foreground GREEN
Write-Host ""

Thursday, August 12, 2010

Quickly create a blank file to fill disk space

I had a need today to test a disk space threshold alert and needed to fill up my hard drive. I started by copying files over and over, but that was taking a long time. A little searching and I found fsutil.exe

fsutil file createnew <filename> <bytes>

This quick little command will create a file of the specified size. Just view the hard disk properties for the amount of free space (which it kindly provides in bytes), subtract a few to keep from maxing it out, and run fsutil.