Space reclaimer

Welcome Forums General PowerShell Q&A Space reclaimer

This topic contains 2 replies, has 3 voices, and was last updated by

 
Participant
2 years, 8 months ago.

  • Author
    Posts
  • #34477

    Participant
    Points: 0
    Rank: Member

    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[]($ArraySize)
    $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 1024*1024*1024) {
    $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
    }

  • #34579

    Keymaster
    Points: 8
    Rank: Member

    Well, rather than posting the script that works, it might be helpful to see the script that isn't working :).

  • #34587

    Participant
    Points: 0
    Rank: Member

    You've essentially asked us to guess what's wrong with your invisible script. For instance there is a space in the text of your message above between the 10 and the GB. But we don't know how it is in your script since you didn't show us. Also it would have been helpful to list any error messages. "... the script then fails" doesn't give us anything to go on.

The topic ‘Space reclaimer’ is closed to new replies.