Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Param(
- [string]$pathToPackages
- )
- Add-Type -AssemblyName System.IO.Compression.FileSystem
- function Unzip
- {
- param([string]$zipfile, [string]$outpath)
- [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
- }
- function ZipDirectory
- {
- param([string]$zipfilename, [string]$sourcedir)
- $compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal
- [System.IO.Compression.ZipFile]::CreateFromDirectory($sourcedir, $zipfilename, $compressionLevel, $false)
- }
- function RemoveBinFiles
- {
- param([string]$path, [string]$updateFile)
- $packageNameOnly = "$($path)\$($updateFile)"
- $package = "$($packageNameOnly).update"
- $packageDirectory = "$($path)\package"
- $packageZip = "$($packageDirectory).zip"
- $packageBin = "$($packageDirectory)\addedFiles\bin"
- $packagePropertiesBin = "$($packageDirectory)\properties\addedFiles\bin"
- Unzip $package $path
- if (Test-Path $packageDirectory) {
- Remove-Item $packageDirectory -recurse
- }
- Unzip $packageZip $packageDirectory
- Remove-Item $packageZip
- if (Test-Path $packageBin) {
- Remove-Item $packageBin -recurse
- }
- if (Test-Path $packagePropertiesBin) {
- Remove-Item $packagePropertiesBin -recurse
- }
- ZipDirectory $packageZip $packageDirectory
- if (Test-Path $packageDirectory) {
- Remove-Item $packageDirectory -recurse
- }
- if (Test-Path $package) {
- Remove-Item $package
- }
- New-Item -ItemType directory -Path $packageNameOnly
- Move-Item -Path $packageZip -Destination $packageNameOnly
- ZipDirectory $package $packageNameOnly
- if (Test-Path $packageNameOnly) {
- Remove-Item $packageNameOnly -recurse
- }
- }
- Get-ChildItem $pathToPackages -Filter *.update |
- Foreach-Object {
- $packageName = $_.BaseName
- Write-Host $packageName
- RemoveBinFiles $pathToPackages $packageName
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement