VMware Cloud Community
yashatrevm
Enthusiast
Enthusiast
Jump to solution

RuntimeException, FullyQualifiedErrorId : MethodNotFound while executing the script

Hi All,
I am trying to execute the following code

$vmName = Read-Host "Enter the VM Name or regex (VMname*) :"
$vmList = Get-VM $vmName

#Create new Virtual Machince Config Spec
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec

#Write new config options to VMs
foreach ($vm in $vmList){

$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.tools.toolsUpgradePolicy = "upgradeAtPowerCycle"

$vm.ReconfigVM_Task($vmConfigSpec)
}

======

However, when I execute this code, I hit the following :

=====

Method invocation failed because [VMware.VimAutomation.ViCore.Impl.V1.VM.UniversalVirtualMachineImpl] does not contain a method named 'ReconfigVM_Task'.
At C:\Users\yash.atre\MyScripts\1_test.ps1:14 char:2
+ $vm.ReconfigVM_Task($vmConfigSpec)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound

=====

The closest understanding to which I could come is that it might be because I am handling multiple VMs starting with same text, however, that is a requirement. I would greatly appriciate if someone could help me fix this issue.

Thank you

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You are calling a vSphere method of the VirtualMAchine object, while the object you are using is a .NET object returned by Get-VM.
The .NET object maps to the vSphere object via the ExtensionData property.
You could do

$vm.ExtensionData.ReconfigVM_Task($vmConfigSpec)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

2 Replies
LucD
Leadership
Leadership
Jump to solution

You are calling a vSphere method of the VirtualMAchine object, while the object you are using is a .NET object returned by Get-VM.
The .NET object maps to the vSphere object via the ExtensionData property.
You could do

$vm.ExtensionData.ReconfigVM_Task($vmConfigSpec)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

yashatrevm
Enthusiast
Enthusiast
Jump to solution

You are a knowledge bank! Thanks a ton for this information.

Kind regards.

Reply
0 Kudos