Advertisement
Guest User

Untitled

a guest
Apr 6th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # This works perfectly
  2. $src = "C:\temp\test"
  3. $dst = "C:\temp\test.zip"
  4. [Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem")
  5. [System.IO.Compression.ZipFile]::CreateFromDirectory($src,$dst)
  6.  
  7. # This fails with: 'Exception calling "CreateFromDirectory" with "2" argument(s): "Could not find a part of the path 'S:\test.zip'."
  8. $user = "[username]"
  9. $pass = ConvertTo-SecureString "[password]" -AsPlainText -Force
  10. $creds = New-Object System.Management.Automation.PSCredential ($user, $pass)
  11. $psDrive = New-PSDrive -Name "S" -PSProvider FileSystem -Root $sourcePath -Credential $creds
  12. $src = "S:\temp\test"
  13. $dst = "S:\temp\test.zip"
  14. [Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem")
  15. [System.IO.Compression.ZipFile]::CreateFromDirectory($src,$dst)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement