title: Several folders into a zip with PowerShell
body: <p>I have several folders <code>dir_01</code>, <code>dir_02</code>, <code>dir_03</code> that I want to backup in a zip file, say, <code>backup.zip</code>. This has to be saved in a folder with today's date. I need to get a .bat file to do the job; no additional third party executables allowed.     </p>
  
  <p><a href="https://stackoverflow.com/questions/34711612/how-do-i-make-a-folder-with-todays-date-and-then-copy-a-file-to-it">Here</a> I found how to create a folder with today's date, but I am having problems to pass <code>$destination</code> to <code>-DestinationPath</code>. I created a .bat that calls PowerShell. Code giving me problems:</p>
  
  <pre><code>powershell.exe $destination = New-Item -Path 'C:\path\to\destionation' -ItemType Directory -Name ("$(Get-Date -f yyyy-MM-dd)")
  
  powershell.exe -nologo -noprofile -command Compress-Archive -Path 'C:\path\dir_01', 'C:\path\dir_02', 'C:\path\dir_03' -DestinationPath $destination\backup.zip -Force
  </code></pre>
  
  <p>The error message is the following:</p>
  
  <pre><code>New-Object : Exception calling ".ctor" with "2" argument(s): "Access to the path 'C:\backup.zip' is denied."
  At
  C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1:729
  char:30
  + ... ileStream = New-Object -TypeName System.IO.FileStream -ArgumentList $ ...
  +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodInvocationException
      + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
  </code></pre>
  
  <p>However, the code works if I hard-code the path to destination, like this:</p>
  
  <pre><code>powershell.exe -nologo -noprofile -command Compress-Archive -Path 'C:\path\dir_01', 'C:\path\dir_02', 'C:\path\dir_03' -DestinationPath 'C:\whole\path\backup.zip' -Force
  </code></pre>
  
  <p>But doing so, I'm unable to save <code>backup.zip</code> in today's folder. </p>
  
  <p><strong>Question:</strong> How can I save <code>backup.zip</code> in the folder that I created with today's date? </p>