Setting source from PSDrive -PSProvider ViMdatastore

Aug 4, 2011 at 2:01 PM

Hi,

I am copying content of VMware datastore.

 

get-vm $VM | get-snapshot -Name "backupV0" | Remove-Snapshot -Confirm:$false -ErrorAction SilentlyContinue

$ds = Get-VM $VM | Get-Datastore -ErrorVariable Err -ErrorAction SilentlyContinue

New-PSDrive -Name myds -PSProvider ViMdatastore -Root '\' -location $ds -ErrorVariable Err -ErrorAction SilentlyContinue

copy-datastoreitem myds:\$VM\$($file.name) -destination y:\$VM-fullvm -recurse -Force -ErrorVariable Err -ErrorAction SilentlyContinue

 

Last line works perfectly well without compression but when I try to set:

 

$zipfile = new-object Ionic.Zip.ZipFile

$zipfile.AddDirectory("myds:\$VM")

 

in the loop I have the following:

Exception calling "AddDirectory" with "1" argument(s): "The given path's format
is not supported."
At line:1 char:22
+ $zipfile.AddDirectory <<<< ("myds:\QCEWVCDB01")
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
 + FullyQualifiedErrorId : DotNetMethodException

 

Similar for .AddFile. Is usage of psdrive supported?

Thanks,

Jakub

Coordinator
Aug 4, 2011 at 2:26 PM

No, I've never used DotNetZip in powershell with a PSDrive. To be honest I don't know exactly what a PSDrive is.

There is some logic in the library to handle drive letters; it assumes drives are single letters. 

Aug 5, 2011 at 5:26 AM

Thanks for the hint, drives should be indeed single letters.

PSDrive is a Windows PowerShell drive that is "mapped" to or associated with a location in a data store, such as a network drive, a directory on the local computer, or a registry key. Windows PowerShell drives are known only to Windows PowerShell. You cannot access them by using Windows Explorer, Windows Management Instrumentation (WMI), Component Object Model (COM), or the Microsoft .NET Framework, or by using tools such as Net Use.

That is a problem I guess. When I name the PSDrive with single letter (i.e. M), I am able to point file in $zipfile.addfile, but no file attributes are being read (date is 00/00/0000 and so on), while trying to $zipfile.adddirectory, error message says that it cannot find part of path.

Coordinator
Aug 5, 2011 at 4:11 PM

So if I understand correctly, a PSdrive is an abstraction that is defined by Powershell.  DotNetZip would need to be "hip" to that new abstraction, in order to deal with it successfully.

Currently DotNetZip deals with the abstractions known as "files" and "directories".   It does not know about psdrives. 

I don't really understand what a psdrive gives you over an actual drive letter (from "net use"); but without getting into all that, can you not just "net use" in powershell and use dotnetzip that way?

I suppose there's an opportunity for some savvy powershell hacker to develop dotnetzip cmdlets or something that know what to do with psdrives. But I don't think that savvy someone is ME.

 

 

Aug 5, 2011 at 5:10 PM

Correct.

What I am gaining by using PSdrive is that I am accessing remotely VMFS datastore located on VMware ESXi server (by using -PSProvider ViMdatastore, which comes with PowerCLI - VMware add-on to Powershell). It is not a network drive and personally I cannot think of any other way to access VMware datastore directly from Powershell.

Thanks for your support!

Coordinator
Aug 5, 2011 at 7:10 PM

Well if you cannot produce an NTFS abstraction over the VMFS, then maybe you should try to produce a stream abstraction over an object stored in the ViMdatastore.  Using streams, DotNetZip will (should) work.  The library can load zips from streams, and write zips to streams.  It can get entry content to streams, and can unpack entries into streams.  Maybe a System.IO.Stream over VMFS is  the answer.