Automation

 View Only
  • 1.  Cloning VMs to alternate datastore

    Posted May 09, 2022 05:02 PM

    I'm trying to clone a list of VM's to an alternate datastore, I have a list of VM's in a .CSV file.

     

    ## Connect-VIServer vcenter.server
    $VMHost = "hostname.test"

    $srcvms = Import-Csv -Path ./Documents/vmnames.csv -UseCulture | select -ExpandProperty VM

    Foreach ($srcvm in $srcvms) {

    new-vm -name "clone_$srcvm" -VM $srcvm -VMHost $VMHost -Datastore "test" -DiskStorageFormat Thin -RunAsync

    }
     
    My variable returns hostname.test, I am connected to my vCenter, but it's barking about the $VMhost variable..
     
    new-vm -name "clone_$srcvm" -VM $srcvm -VMHost '$VMHost'
    | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    | 5/9/2022 12:52:48 PM New-VM Please specify at least one of the following parameters: "ResourcePool" or "VMHost".
     
    All the hosts have the test datastore mounted, can I forego the VMhost requirement or what am I doing wrong?
     
    Thanks,
     
    Greg


  • 2.  RE: Cloning VMs to alternate datastore
    Best Answer

    Posted May 09, 2022 05:32 PM

    Did you already try with changing that line to

     

    Adding the Verbose switch, and/or the WhatIf switch, on the New-VM cmdlet might provide some more feedback.
    For testing I would in any case remove the RunAsync switch



  • 3.  RE: Cloning VMs to alternate datastore

    Posted May 09, 2022 07:55 PM

    That worked.  Thanks a bunch..