DenaliHardtail
DenaliHardtail

Reputation: 28336

How do I use a UNC path in a powershell script?

I have some powershell code that calls WinZip and makes an archive.

$program = "c:\program files (x86)\WinZip\WZZIP.EXE"

& $program -a -P -r c:\temp\test.zip ("\\server.domain.com\FirstName LastName\ProjectId\*.*")

The two backslashes are part of a UNC path. I must use UNC and a fully qualified domain name.

The above code attempts to run but hangs until I kill it (press the stop button in ISE).

When I wrap the UNC path in parenthesis, again the code attempts to run but hangs.

How do I fix this? I'm stuck with UNC paths and using WinZip.

Upvotes: 0

Views: 2855

Answers (2)

Brent
Brent

Reputation: 118

While not a direct answer to your question, perhaps you could use the PowerShell module PowerShellZIP at CodePlex (http://powershellzip.codeplex.com/) to create the ZIP files for you.

Then you can use the full powershell pipeline to create the ZIP files rather than calling out to WinZip.

I haven't tested to see if this module can zip files from an UNC path tho..

Upvotes: 1

Apothis
Apothis

Reputation: 426

UNC paths are not supported in WinZip from the command line. You will need to map a drive letter to the UNC path before preforming the zip. You can easily script this:

net use s: "\\server.domain.com\FirstName LastName\ProjectId\"

Alternatively, you can copy the files locally, zip them, then delete them from the local copy leaving only your zip file.

I believe 7zip does not have this limitation and is generally capable of doing everything WinZip is and more.

Upvotes: 1

Related Questions