Skip to content

Instantly share code, notes, and snippets.

@p0w3rsh3ll
Last active July 25, 2016 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save p0w3rsh3ll/56a345faff6fa06c70239d5846b82944 to your computer and use it in GitHub Desktop.
Save p0w3rsh3ll/56a345faff6fa06c70239d5846b82944 to your computer and use it in GitHub Desktop.
Get-ChildItem -Path $PSTranscripts -Directory | Where { $_.LastWriteTime -lt (Get-Date).AddDays(-1) } |
ForEach-Object {
$StartTime = Get-Date
$FSize = '{0:N2}' -f ((Get-ChildItem -Path $_.FullName -Depth 1 -Recurse | Measure -Property Length -Sum).Sum / 1MB)
try {
Compress-Archive -Path $_.FullName -DestinationPath "$($_.FullName).zip" -CompressionLevel Optimal -Force -ErrorAction Stop
Get-Item -Path $($_.FullName) | Remove-Item -Force -Recurse -Confirm:$false -ErrorAction Stop
} catch {
Write-Warning -Message "Failed because $($_.Exception.Message)"
}
if (Test-Path -Path "$($_.FullName).zip") {
$Zsize = '{0:N2}' -f ((Get-ChildItem -Path "$($_.FullName).zip").Length/1MB)
$Elpased = (New-TimeSpan -Start $StartTime -End (Get-Date)).ToString()
$ratio = '{0:N2}' -f $FSize/$Zsize
Write-Verbose "It took $Elpased to compress $($_.Name) with a ratio of $ratio : $FSize MB to $Zsize MB zip" -Verbose
} else {
Write-Warning -Message "Skipping $($_.FullName).zip)"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment