Hi guys.
Has anyone had any luck in cloning vApp options from one VM to another?
The reason I ask is that as part of a DR scenario our VMs datastore will be cloned to another vCenter and the vApp options don't follow it.
Its another discussion if that is actually a issue or not.
I have been trying to use the script from William Lam https://www.virtuallyghetto.com/2017/10/updating-ovf-properties-for-a-vm-using-vsphere-api-and-power...
However, no matter what I do, I cant get it to actually set anything.
I created a little test to try on a few different environments I have and the same thing happens.
Basically it grabs the source config from a VM and then tries to set it on a cloan of that VM thats had its vApp info removed.
My test is using the following code from Mr Lam vghetto-scripts/VMOvfProperty.ps1 at master · lamw/vghetto-scripts · GitHub
I clone the vApp machine.
I then go to the VM, go to VApp and untick the box. This then asks me to confirm that all these settings will be deleted.
I then run the following code using the functions mentioned.
$srcVM = Get-VM -Name "VM"
$destVM = Get-VM -Name "CloanVM"
$ovfConfig = Get-VMOvfProperty -VM $srcVM
Set-VMOvfProperty -VM $destVM -ovfChanges $ovfConfig
When I go to the VM the vApp option is ticked. However none of the settings have moved over.
When I run
Get-VMOvfProperty -VM $srcVM
I get all the vApp options
When i run
Get-VMOvfProperty -VM $destVM
I get nothing
I have tried this with vRealize Log Insight machine as well. Same result.
My PowerCLI is 6.5 build 6234650. My hosts are 6.0 U3 and my vCenter is 6.5 on all environments I have tested.
I tried to do it from another angle getting the data using ExtensionData.VAppConfig but, whilst I can get the info I need, I have failed to successfully set it.
Why do you delete the properties?
Afaik William's Set-VMOvfProperty function changes values in the OVF properties, but it does not create new OVF properties.
You would need a New-VMOvfProperty function to create new properties.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD. Thanks for having a look.
It was just for a test to remove the existing ones to try and add them back on. When the VM is moved to another vCenter all these settings are lost.
Basically what I want to do is export the settings to a CSV and then apply them to the VM at the other side.
Exporting them is fairly easy using ExtensionData.Config.VAppConfig.Property
But I am really struggling to add anything back in.
I thought I recognised your name . I have your book and read your blog.
I was using one of your examples I found in this forum yesterday.
I tried playing around with your script How to rebuild vROps vApp Container Data from PowerCLI
I used it to find my VMs and export all the info to a CSV
However I never got importing to work. No matter what I did I kept ending up with
"The property 'Property' cannot be found on this object. Verify that the property exists and can be set."
which refers to $spec.Property += $prop
I tried changing it from $prop = New-Object VMware.Vim.VAppPropertySpec to $prop = New-Object VMware.Vim.VirtualMachineConfigSpec and various other things as a shot in the dark. It wasn't a very successful night.
The actual VM in question isnt an actual vApp. Rather it was an ova with details stored under vApp for deployment (similar to Loginsight etc)
Before I do some testing in my lab, is that a specific vApp with specific/special properties?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It seems to be every ova with deployment options I have tested. So not a vApp as such, but a VM with vApp properties.
I think this is where the confusion lies.
For example I have tried, as a test, to duplicate the vApp options for LogInsight and the vCenter Server Support Assistant and put it on another VM
So in the case of the support assistant when i do:
$srcVM = Get-VM -Name "vCenterSupportAssistant"
$vappProperties = $srcVM.ExtensionData.Config.VAppConfig.Property | Export-Csv C:\tmp\VM.csv -NoTypeInformation -UseCulture
I get a csv with the options you would expect.
When i try to import it to another non vApp VM (using your script) that's when I get the error
"The property 'Property' cannot be found on this object. Verify that the property exists and can be set."
Sorry the error is different. That was from one of my many failed attempts.
The error is:
You cannot call a method on a null-valued expression. on $dstVApp.ExtensionData.UpdateVAppConfig($spec)
(your) Code is
# Export vApp properties
$srcVM = Get-VM -Name "vCenterSA"
$destVM = Get-VM -Name "VM_TEST_2"
$vappProperties = $srcVM.ExtensionData.Config.VAppConfig.Property | Export-Csv C:\tmp\VM.csv -NoTypeInformation -UseCulture
# Import vApp properties
$spec = New-Object VMware.Vim.VAppConfigSpec
Import-Csv "c:\tmp\VM.csv" -UseCulture | %{
$prop = New-Object VMware.Vim.VAppPropertySpec
$prop.Info = New-Object VMware.Vim.VAppPropertyInfo
$prop.Info.Category = $_.Category
$prop.Info.ClassId = $_.ClassId
$prop.Info.DefaultValue = $_.DefaultValue
$prop.Info.Description = $_.Description
$prop.Info.Id = $_.Id
$prop.Info.InstanceId = $_.InstanceId
$prop.Info.Key = $_.Key
$prop.Info.Label = $_.Label
$prop.Info.Type = $_.Type
$prop.Info.TypeReference = $_.TypeReference
$prop.Info.UserConfigurable = $_.UserConfigurable
$prop.Info.Value = $_.Value
$spec.Property += $prop
}
$dstVApp.ExtensionData.UpdateVAppConfig($spec)
When I check that the info is going in OK i do:
$prop.Info
Key : 7
ClassId : vami
InstanceId : VMware_vCenter_Support_Assistant_Appliance
Id : gateway
Category : Networking Properties
Label : Default Gateway
Type : string
TypeReference :
UserConfigurable : True
DefaultValue :
Value : x.x.x.x
Description : The default gateway address for this VM. Leave blank if DHCP is desired.
I think there is a mix up between $dstVapp and $destVM?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Sorry typo. Too many edits..
Method invocation failed because [VMware.Vim.VirtualMachine] does not contain a method named 'UpdateVAppConfig'.
+ $dstVM.ExtensionData.UpdateVAppConfig($spec)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
You can only use the UpdateVAppConfig method on a vApp, not on a VM.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thats what I figured going by the error.
So i tried ExtensionData.ReconfigVM_Task like Williams script to update the vApp options for a VM
But I didn't get very far. I also thought I was using his script wrong, so I created the post here to see if I was doing it wrong.