ARJNIG123
Contributor
Contributor

Hi LucD:

Sorry, picking up on an old thread and also I am not savy with PowerCLI so please pardon if my question is fundamentally flawed.

"$vm = Get-VM -Name MyVM" This works when VM is registered. Correct?

Therefore, for unregistering a VM "Remove-VM -VM $vm -DeletePermanently:$false -Confirm:$false" will work.

However, when VM is already unregistered, "$vm = Get-VM -Name MyVM" will probably not work. Then while registering that VM, how the extension data will come in "New-VM -VMFilePath $vm.ExtensionData.Config.Files.VmPathName -ResourcePool $rp -Confirm:$false"?

I am interested in a scripted method of registering multiple VMs from different datastores either on one host or multiple hosts of same cluster (if we can use cluster instead of VMHost). My scenario is I have multiple Active-Active pairs of Datastores. VMs are registered on one site. We failover by unregistering VMs > Go to other site > Browse Datastore and register VM. I came across a function that gives me all VMX File paths for all VMs I am interested in. However, so far I have been able to use vmx file path '[DatastoreName] VMName/VMName.vmx' in a one liner (per VM) format -- New-VM -VMHost xxxxxxx.domain.com -VMFilePath '[DatastoreName] VMName/VMName.vmx'

The function provides path for multiple VMs as follows:

'[Datastore1Name] VM1Name/VM1Name.vmx'

'[Datastore1Name] VM2Name/VM2Name.vmx'

'[Datastore2Name] VM3Name/VM3Name.vmx'

I intend to simply use this information in a way which is not one-line command at a time (per-VM).

 

 

I tried something like creating a text file with vmx file paths as:

'[Datastore1Name] VM1Name/VM1Name.vmx'

'[Datastore1Name] VM2Name/VM2Name.vmx'

'[Datastore2Name] VM3Name/VM3Name.vmx'

 

And then do Get-Content to get all paths and then run Foreach loop for each path providing single ESXi host like below:

$VMXpaths = Get-Content H:\Temp\VMXPaths.txt

Foreach ($VMXpath in $VMXpaths){
   New-VM -VMHost xxxxxx.domain.com -VMFilePath $VMXpath
}

But no luck.

Please advise what you think can be done here.

 

 

Thanks.

 

Reply
0 Kudos