Hi Guys,
I have found this Space reclaimer script on net, Its works fine, But I would like to generate more large file e.g 10 GB. I have changed the $ArraySize = 1024kb for 10 GB, but the script then fails. Any advise ?
param (
[string] $FilePath,
[string] $LogFile,
[int] $CycleWait
)
Function DispMessage ([string] $Message) {
[string] $DateStamp = get-date -format “yyyy-MM-dd HH:mm.ss”
Write-Host “[$DateStamp] $Message”
Add-Content $LogFile “[$DateStamp] $Message”
}
Function SleepWait ([string] $Sleeptime) {
sleep $Sleeptime
DispMessage " –> Sleeping $Sleeptime sec"
}
$LogFile = “C:\temp\NimbleFastReclaim.log”
$FilePrefix = “NimbleFastReclaim”
$FileExt = “.tmp”
If ($FilePath -eq “”) {
Write-Host "- Filepath "
Write-Host “- LogFile (DEFAULT=$LogFile)”
Write-Host “- CycleWait(s) (DEFAULT=0)”
Exit 1
}
If ($FilePath.substring($FilePath.length - 1, 1) -ne "") {
$FilePath = $FilePath + ""
}
$ArraySize = 1024kb
$WriteLoops = 1024
DispMessage "–> Starting Reclaim on $Filepath … "
DispMessage “–> Cycle Sleep = $CycleWait sec”
DispMessage “–> File Size = $($ArraySize*$WriteLoops/1024/1024) MB”
$SourceFile = “$($FilePath)$($FilePrefix)0$($FileExt)”
Try {
DispMessage " –>Writing $SourceFile"
$ZeroArray= new-object byte
$Stream= [io.File]::OpenWrite($SourceFile)
For ($i=1; $i -le $WriteLoops; $i++) {
$Stream.Write($ZeroArray,0, $ZeroArray.Length)
}
$Stream.Close()
$copyidx = 1
while ((gwmi win32_volume | where {$.name -eq “$FilePath”}).Freespace -gt 102410241024) {
$TargetFile = “$($FilePath)$($FilePrefix)$($copyidx)$($FileExt)”
DispMessage " –> Writing $TargetFile"
cmd /c copy $SourceFile $TargetFile
$copyidx = $copyidx + 1
If ($CycleWait -gt 0) {
SleepWait $CycleWait
}
}
DispMessage “–> Reclaim Complete. Cleaning up…”
Remove-Item “$($FilePath)$($FilePrefix)$($FileExt)"
DispMessage "–> DONE! Zerod out $($copyidx$ArraySize/1024/1024) GB”
}
Catch {
DispMessage “##> Reclaim Failed. Cleaning up…”
Remove-Item “$($FilePath)$($FilePrefix)*$($FileExt)”
$ex = $.Exception
Dispmessage “##Error: SQL Connection Check failed” $true
Dispmessage $ex.message $true
$ex = $ex.InnerException
while ($ex.InnerException)
{
Dispmessage $ex.InnerException.message $true
$ex = $ex.InnerException
}
Exit 1
}