Add ReZip Parameter for MSOnline compatability

This commit is contained in:
JustinGrote
2018-04-09 14:35:28 -07:00
parent b5177de50d
commit 243ba0bb3c

View File

@@ -400,7 +400,8 @@
# [Parameter(ParameterSetName = 'TableNow')]
[Switch]$Now,
[Switch]$ReturnRange,
[Switch]$NoTotalsInPivot
[Switch]$NoTotalsInPivot,
[Switch]$ReZip
)
Begin {
@@ -1000,7 +1001,26 @@
$ws.Dimension.Address
}
$pkg.Save()
if ($ReZip) {
write-verbose "Re-Zipping $($pkg.file) using .NET ZIP library"
$zipAssembly = "System.IO.Compression.Filesystem"
try {
Add-Type -assembly $zipAssembly -ErrorAction stop
} catch {
write-error "The -ReZip parameter requires .NET Framework 4.5 or later to be installed. Recommend to install Powershell v4+"
continue
}
$TempZipPath = Join-Path -path ([System.IO.Path]::GetTempPath()) -ChildPath ([System.IO.Path]::GetRandomFileName())
[io.compression.zipfile]::ExtractToDirectory($pkg.File,$TempZipPath) | Out-Null
Remove-Item $pkg.File -Force
[io.compression.zipfile]::CreateFromDirectory($TempZipPath,$pkg.File) | Out-Null
}
$pkg.Dispose()
if ($Show) {