PowerCLI

 View Only
Expand all | Collapse all

copy-datastoreitem

  • 1.  copy-datastoreitem

    Posted Nov 25, 2009 03:47 PM

    Hi all,

    I've just installed the latest PowerCLI in order to get my hands on the copy-datastoreitem cmdlet. As I'm not very knoweldgable regarding powershell, I read the example and wrote the following

    Connect-VIServer -Server inf-vc.qavdc.com -User administrator -Password password

    $datastore1 = "SharedVMs"

    $datastore2 = "SharedTMPLs"

    Copy-DatastoreItem -Item $datastore2:\VM2GTemplate\* -Destination $datastore1:\VM2GTemplate -Force

    This executes without any errors, but does not appear to do anything. The example in the help file talks about the datastore provider but does not elaborate. I've tried get-view against the datastore with and without the ID function to see if that would get whatever information this cmdlet wants, but no luck.

    Help!!!!!!!!



  • 2.  RE: copy-datastoreitem

    Posted Nov 25, 2009 06:30 PM

    Afaik this cmdlet requires a PSDrive when your source or destination is a datastore.

    Something like this

    
    $ds = Get-Datastore <datastore-name>
    New-PSDrive -Name MyDS -PSProvider ViMdatastore -Root '\' -location $ds
    Copy-DatastoreItem C:\Temp\test.txt -Destination MyDS:\Folder2\
    
    

    If you want to copy between two different datastores you will have to create two psdrives.

    If you want to copy on one datastore between different folders you can do

    
    Copy-DatastoreItem MyDS:\Folder1\test.txt -Destination MyDS:\Folder2\
    
    

    Btw there is a section on the PowerCLI datastore provider in the vSPhere PowerCLI Administration Guide that is installed on the client where you instelled PowerCLI 4u1.



  • 3.  RE: copy-datastoreitem

    Posted Nov 25, 2009 08:46 PM

    Hi Luc,

    This works great

    $ds1 = Get-Datastore SharedVMs

    $ds2 = Get-Datastore SharedTMPLs

    New-PSDrive -Location $ds1 -Name source -PSProvider VimDatastore -Root '\'

    New-PSDrive -Name dest -PSProvider ViMdatastore -Root '\' -location $ds2

    Copy-DatastoreItem dest:\VM2GTemplate\* -Destination source:\VM2GTemplate\ -Recurse -Force

    One small weirdity. This works perfectly from the PowerCLI command line, but not from within the PowerGUI script editor, but I suspect that it's something to do with updating the toolkit, but the version of the Vmware.VimAutomation.Core library being loaded by PowerGUI is the previous one.



  • 4.  RE: copy-datastoreitem

    Posted Nov 25, 2009 09:05 PM

    Yes, the Copy-DatastoreItem cmdlet is new in the latest build.

    Perhaps you could try asking how to load the latest library in PowerGui in the PowerGui forums.



  • 5.  RE: copy-datastoreitem

    Posted Nov 25, 2009 09:10 PM

    This is where the weirdity comes in, cause it's not the Copy-DataStoreItem that has an issue, it's New-PSDrive that throws the error.

    Cannot find drive. A drive with name 'vmstores' does not exist.

    At :line:261 char:12

    + New-PSDrive <<<< -Location $ds1 -Name source -PSProvider VimDatastore -Root '\'

    Cannot find drive. A drive with name 'vmstores' does not exist.

    At :line:269 char:12

    + New-PSDrive <<<< -Name des

    The same script runs perfectly if I run it using the command line. tres Weird, n'est pas?



  • 6.  RE: copy-datastoreitem

    Posted Nov 25, 2009 09:31 PM

    That's probably because the VimDatastore provider is also new from the 4u1.



  • 7.  RE: copy-datastoreitem

    Posted Nov 25, 2009 09:38 PM

    I've posted a question on the PowerGUI website, so hopefully it will get resolved. It's not a show stopper by any means, it's just irriitating that I can't run the debugger on it. Ah well, at least now I have a script that does everything I need and much of the credit belongs to you.

    Once again, thank you for all your help and your great dvSwitch functions.



  • 8.  RE: copy-datastoreitem

    Posted Nov 26, 2009 06:31 AM

    Ok, I should have been more precise. It was there (sort of) but it wasn't really usable :smileywink:

    Some remarks:

    1) It's important to know the difference between vmstores: (all connected vcenters) and vmstore: (the last connected vcenter)

    2) If you have folders in the root of your vcenter or between your datacenter and the datastore(s), they have to be included in the path

    3) The path elements are case-sensitive. Although the vSphere client apparently is not (try creating a 'folder' and a 'Folder' for example)

    4) Use the Copy-DatastoreItem cmdlet (instead of Copy-Item) when the source and/or the destination is a datastore

    Would you care to elaborate on the "still not ready for general purpose" ?

    Why do the release notes mention "Files cannot be copied in or out the Datastore Provider" under Datastore Provider in the Known Issues ?



  • 9.  RE: copy-datastoreitem

    Posted Nov 26, 2009 06:10 PM

    Would you care to elaborate on the "still not ready for general purpose" ?

    Why do the release notes mention "Files cannot be copied in or out the Datastore Provider" under Datastore Provider in the Known Issues ?

    As for "not ready", Get-Content and Set-Content don't work, Copy-Item doesn't work (though supposedly this is a PowerShell limitation), etc. A lot of the stuff you expect a provider to do don't work yet.

    Also, try running Get-Childitem -Recurse -Include *.vmx, wait an hour and report back. The thing can be mind-numbingly slow at times. Hadn't noticed about the case sensitivity. Given ESX's Linux underpinnings I would expect it to be case sensitive and they did something in vSphere Client to attempt to deal with that.

    I think the reference in the docs about no ability to copy refers to Copy-Item not working. Clearly you can copy with our purpose-built cmdlet.

    =====

    Carter Shanklin

    Read the PowerCLI Blog
    [Follow me on Twitter|http://twitter.com/cshanklin]



  • 10.  RE: copy-datastoreitem

    Posted Nov 26, 2009 07:04 PM

    Carter, thanks for the information.



  • 11.  RE: copy-datastoreitem

    Posted Nov 25, 2009 11:58 PM

    Can you see if using the vmstore or vmstores drive directly solves the problem? If you know your datacenter and datastore the path will be of the form vmstore:\datacenter\datastore\path-within-datastore

    =====

    Carter Shanklin

    Read the PowerCLI Blog
    [Follow me on Twitter|http://twitter.com/cshanklin]



  • 12.  RE: copy-datastoreitem

    Posted Nov 25, 2009 11:16 PM

    Actually it's been there but it hadn't quite reached half-baked status so we didn't talk about it much.

    It's much improved now and more prominent. It's still not ready for general purpose use but is good for some casual poking around at your datastores.

    Also, a new goodie that's really helpful, whenever you connect a provider named vmstore is created that maps your datastores. To get to it type:

    cd vmstore:

    and you'll see a filesystem view of all your datastores.

    You can read all about this by running

    help about_vimdatastore

    =====

    Carter Shanklin

    Read the PowerCLI Blog
    [Follow me on Twitter|http://twitter.com/cshanklin]