-
-
Save p0w3rsh3ll/56a345faff6fa06c70239d5846b82944 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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