Created
July 18, 2018 17:18
-
-
Save zeqk/81ff0f8ac215eef6ca6bbd951c6ccd5b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
$path = "test" | |
$filter = "*.config" | |
#To support both absolute and relative paths.. | |
$pathitem = Get-Item -Path $path | |
#If sourcepath exists | |
if($pathitem) { | |
#Get name for tempfolder | |
$tempdir = Join-Path $env:temp "CompressArchiveTemp" | |
#Create temp-folder | |
New-Item -Path $tempdir -ItemType Directory -Force | Out-Null | |
#Copy files | |
Copy-Item -Path $pathitem.FullName -Destination $tempdir -Filter $filter -Recurse | |
#Get items inside "rootfolder" to avoid that the rootfolde "test" is included. | |
$sources = Get-ChildItem -Path (Join-Path $tempdir $pathitem.Name) | Select-Object -ExpandProperty FullName | |
#Create zip from tempfolder | |
Compress-Archive -Path $sources -DestinationPath config-files.zip | |
#Remove temp-folder | |
Remove-Item -Path $tempdir -Force -Recurse | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment