I found powershell has compress-archive cmdlet from How do I exclude a folder in compress-archive; however, if I pass powershell argument into the -exclude parameter, it is not working. If it call from powershell variable it is working. Am I missing something? Please advise.
This script is not working. Here is powershell parameters
.\createzipfile.ps1 "C:\temp" "C:\Myzipdir" myzipfile.zip '"web.config","PageBase.master"'
Param
(
[string]$source,
[string]$destination,
[string]$zipfilename,
[string]$excludefilepattern
)
cls
$zipfile = $destination + "\" + $zipfilename
$files = Get-ChildItem -Path $source -Exclude $excludefilepattern
# compress
#Compress-Archive -Path $files -DestinationPath $zipfile -CompressionLevel Fastest
Compress-Archive -Path $files -DestinationPath $zipfile -CompressionLevel Fastest
This script is working but I really do need to have -exclude passing from powershell parameter
.\createzipfile.ps1 "C:\temp" "C:\Myzipdir" myzipfile.zip
Param
(
[string]$source,
[string]$destination,
[string]$zipfilename
)
cls
$zipfile = $destination + "\" + $zipfilename
$exclude = ("web.config","PageBase.master")
$files = Get-ChildItem -Path $source -Exclude $exclude
# compress
Compress-Archive -Path $files -DestinationPath $zipfile -CompressionLevel Fastest
Best Regards, Andy Pham