I'm writing a powershell script in which I would like to .zip a directory with 2 subdirectories. In one of the subdirectories I would like to exclude another directory.
myDirectory
-- sub 1
--- sub 1.1
--- sub 1.2
-- sub 2
--- sub 2.1
--- sub 2.2
I wrote this script but it isn't working. Can anyone give me a hint or tell me what I'm doing wrong?
$ChildItemPath = "myDirectory"
$Date = [DateTime]::Now.ToString("yyyyMMdd-HHmmss")
$Exclude = @("myDirectory/sub 2/sub 2.1")
$DestinationPath = "Archive-v" + $Date
$CompressPath = Get-ChildItem -Path $ChildItemPath -Exclude $Exclude
Compress-Archive -Path $CompressPath -DestinationPath $DestinationPath -update
the .bat/.ps1 file is in the same directory as 'myDirectory'
-------------------------- EDIT 19:55 -------------------------- Solution of suggested by Reza works fine when subfolder is pretty 'small'. I'm trying to exclude 'node_modules' from a AngularClient-dir.
So the final .zip file contains a 'serverside'-dir: vs217 asp.net core project and a 'clientside'-dir: angular4 project without the node_modules