Guest User

Untitled

a guest
Jul 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. $path = "test"
  2. $filter = "*.config"
  3.  
  4. #To support both absolute and relative paths..
  5. $pathitem = Get-Item -Path $path
  6.  
  7. #If sourcepath exists
  8. if($pathitem) {
  9. #Get name for tempfolder
  10. $tempdir = Join-Path $env:temp "CompressArchiveTemp"
  11.  
  12. #Create temp-folder
  13. New-Item -Path $tempdir -ItemType Directory -Force | Out-Null
  14.  
  15. #Copy files
  16. Copy-Item -Path $pathitem.FullName -Destination $tempdir -Filter $filter -Recurse
  17.  
  18. #Get items inside "rootfolder" to avoid that the rootfolde "test" is included.
  19. $sources = Get-ChildItem -Path (Join-Path $tempdir $pathitem.Name) | Select-Object -ExpandProperty FullName
  20.  
  21. #Create zip from tempfolder
  22. Compress-Archive -Path $sources -DestinationPath config-files.zip
  23.  
  24. #Remove temp-folder
  25. Remove-Item -Path $tempdir -Force -Recurse
  26. }
Add Comment
Please, Sign In to add comment