Flapoly
Contributor
Contributor

How to set VM options

Jump to solution

How to set VM guest settings with VIPowershell

By exemple I would like to set the "VM Properties/ options / Check and upgrade tools before each power-on" ?

Best regards

0 Kudos
1 Solution

Accepted Solutions
admin
Immortal
Immortal

Hi ykalchev,

I have setup the new Beta1.

I have an error message when created VirtualmachineConfigSpec object... any idea ?

see bellow

PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows> $vmConfigSpec = N

ew-Object VMware.Vim.VirtualMachineConfigSpec

New-Object : Cannot find type : make sure

the assembly containing this type is loaded.

At line:1 char:27

+ $vmConfigSpec = New-Object <<<< VMware.Vim.VirtualMachineConfigSpec

The reason is because the VMware.Vim assembly is not loaded until a call to get-view or find-entityview is made. There are two ways to deal with this:

1. Call get-view or find-entityview before instantiating the object:

PS> $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec

New-Object : Cannot find type http://VMware.Vim.VirtualMachineConfigSpec: make sure

the assembly containing this type is loaded.

At line:1 char:27

+ $vmConfigSpec = New-Object <<<< VMware.Vim.VirtualMachineConfigSpec

PS> $vm = get-view (get-vm Snap*).Id

PS> $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec

PS>

2: Load the assembly manually:

PS> $vmConfigSpec = new-object VMware.Vim.VirtualMachineConfigSpec

New-Object : Cannot find type http://VMware.Vim.VirtualMachineConfigSpec: make sure

the assembly containing this type is loaded.

At line:1 char:27

+ $vmConfigSpec = new-object <<<< VMware.Vim.VirtualMachineConfigSpec

PS> http://System.Reflection.Assembly::LoadWithPartialName("VMware.Vim")

GAC Version Location

--- -


-


True v2.0.50727 C:\WINDOWS\assembly\GAC_MSIL\VMware.Vim\1.0.0.0__10980...

PS> $vmConfigSpec = new-object VMware.Vim.VirtualMachineConfigSpec

PS>

View solution in original post

0 Kudos
3 Replies
ykalchev
VMware Employee
VMware Employee

You can do that using Virtual Infrastructure API and Get-View cmdlet (see )

Try this (using the Beta release):

$vm = Get-View (Get-VM vmname).Id

$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec

$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo

$vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"

$vm.ReconfigVM($vmConfigSpec);

Yasen Kalchev, vSM Dev Team
0 Kudos
Flapoly
Contributor
Contributor

Hi ykalchev,

I have setup the new Beta1.

I have an error message when created VirtualmachineConfigSpec object... any idea ?

see bellow

PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows> $vmConfigSpec = N

ew-Object VMware.Vim.VirtualMachineConfigSpec

New-Object : Cannot find type http://VMware.Vim.VirtualMachineConfigSpec: make sure

the assembly containing this type is loaded.

At line:1 char:27

+ $vmConfigSpec = New-Object <<<< VMware.Vim.VirtualMachineConfigSpec

0 Kudos
admin
Immortal
Immortal

Hi ykalchev,

I have setup the new Beta1.

I have an error message when created VirtualmachineConfigSpec object... any idea ?

see bellow

PS C:\Program Files\VMware\Infrastructure\VIToolkitForWindows&gt; $vmConfigSpec = N

ew-Object VMware.Vim.VirtualMachineConfigSpec

New-Object : Cannot find type : make sure

the assembly containing this type is loaded.

At line:1 char:27

+ $vmConfigSpec = New-Object &lt;&lt;&lt;&lt; VMware.Vim.VirtualMachineConfigSpec

The reason is because the VMware.Vim assembly is not loaded until a call to get-view or find-entityview is made. There are two ways to deal with this:

1. Call get-view or find-entityview before instantiating the object:

PS&gt; $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec

New-Object : Cannot find type http://VMware.Vim.VirtualMachineConfigSpec: make sure

the assembly containing this type is loaded.

At line:1 char:27

+ $vmConfigSpec = New-Object &lt;&lt;&lt;&lt; VMware.Vim.VirtualMachineConfigSpec

PS&gt; $vm = get-view (get-vm Snap*).Id

PS&gt; $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec

PS&gt;

2: Load the assembly manually:

PS&gt; $vmConfigSpec = new-object VMware.Vim.VirtualMachineConfigSpec

New-Object : Cannot find type http://VMware.Vim.VirtualMachineConfigSpec: make sure

the assembly containing this type is loaded.

At line:1 char:27

+ $vmConfigSpec = new-object &lt;&lt;&lt;&lt; VMware.Vim.VirtualMachineConfigSpec

PS&gt; http://System.Reflection.Assembly::LoadWithPartialName("VMware.Vim")

GAC Version Location

--- -


-


True v2.0.50727 C:\WINDOWS\assembly\GAC_MSIL\VMware.Vim\1.0.0.0__10980...

PS&gt; $vmConfigSpec = new-object VMware.Vim.VirtualMachineConfigSpec

PS&gt;

View solution in original post

0 Kudos