PowerShell – Script to run one-time full deduplication including optimization, garbage collection and scrubbing


I wrote a simple script to run full deduplication. It is handy when you need one-time deduplication including garbage collection and scrubbing job.

$ErrorActionPreference = 'Stop'

Function Wait-RvDedupJob
{
    Write-Warning -Message 'Wait for all jobs to finish'
    while (Get-DedupJob -ErrorAction SilentlyContinue)
    {
        Start-Sleep -Seconds 10
    }
}

Get-DedupVolume | ForEach-Object -Process `
{
    $_.Volume

    Wait-RvDedupJob

    $_ | Start-DedupJob -Type Optimization -Priority Normal -Memory 50 -OutVariable job

    Wait-RvDedupJob

    $_ | Start-DedupJob -Type GarbageCollection -Priority Normal -Memory 50 -Full -OutVariable job

    Wait-RvDedupJob

    $_ | Start-DedupJob -Type Scrubbing -Priority Normal -Memory 50 -Full -OutVariable job

    Wait-RvDedupJob
}

Get-DedupStatus |
    Format-Table -Property Volume,
        @{ Expression = { $_.LastOptimizationTime }; Label = 'OptT' },
        @{ Expression = { $_.LastOptimizationResult }; Label = 'OptR' },
        @{ Expression = { $_.LastOptimizationResultMessage.Substring(0, 10) }; Label = 'OptRM' },
        @{ Expression = { $_.LastGarbageCollectionTime }; Label = 'ColT' },
        @{ Expression = { $_.LastGarbageCollectionResult }; Label = 'ColR' },
        @{ Expression = { $_.LastGarbageCollectionResultMessage.Substring(0, 10) }; Label = 'ColRM' },
        @{ Expression = { $_.LastScrubbingTime }; Label = 'ScrT' },
        @{ Expression = { $_.LastScrubbingResult }; Label = 'ScrR' },
        @{ Expression = { $_.LastScrubbingResultMessage.Substring(0, 10) }; Label = 'ScrRM' } -AutoSize

Leave a Reply

Your email address will not be published.

Active Directory Advanced function AlwaysOn Availability Groups AlwaysOn Failover Cluster Instances Building Cloud Cloud Cluster Cmdlet Database Deployment Design DFS Domain Controller DSC Fabric Failover Clustering File Server Group Policy Hardware Profile Host Hyper-V Installation Library Library Asset Library Server Network Operations Manager Orchestrator PowerShell PowerShell User Group PowerShell Workflow Security Service Manager SQL Server Storage System Center Template Time Time Synchronization Tips Virtual Machine Virtual Machine Manager VM Network VM Template Windows Server 2012 R2