VMware Cloud Community
gallopa
Enthusiast
Enthusiast
Jump to solution

Script to update Advanced Options

Hi,

Can anyone help with the powershell script required to update the Advanced Options of a host? In particular I would like to update the value of NFS.MaxVolumes but will likely want to script other updates. I am assuming that the script will be the same for different options with a different key used for each? Any help would be greatly apreciated. Regards, Andrew.

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

It looks as if you're missing the s in the script.

The Communities SW has problems when accessed with IE.

I attached the script to avoid this problem.

Does that work?

Some other points to note:

- you have be connected to the VC. Do a Connect-VIServer first

- use the latest version (build 103777)


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

View solution in original post

0 Kudos
13 Replies
LucD
Leadership
Leadership
Jump to solution

The following script shows how to change the NFS.MaxVolumes setting to 12.

The script can easily be adapted to set multiple settings in 1 run.

$tgtkey = "NFS.MaxVolumes"
$tgtvalue = 12

$esx = Get-View -ViewType HostSystem -Filter @{"Name" = <ESX-host>}
$optMgr = Get-View -Id $esx.ConfigManager.AdvancedOption

$optarr = @()
$option = New-Object VMware.Vim.OptionValue
$option.key = $tgtkey
$option.value = $tgtvalue
$optarr += $option
$optMgr.UpdateOptions($optarr)


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

0 Kudos
sddunne
Contributor
Contributor
Jump to solution

Hi there,

I can't get that script to work, i keep getting the error;

PS C:\boot-config> C:\boot-config\test.ps1

Get-View : The argument cannot be null or empty.

At C:\boot-config\test.ps1:5 char:83

+ $esx = Get-View -ViewType HostSystem -Filter @{"Name" = $h} $optMgr = Get-Vie

w -Id <<<< $esx.ConfigManager.AdvancedOption

New-Object : A parameter cannot be found that matches parameter name '='.

At C:\boot-config\test.ps1:8 char:21

+ $option = New-Object <<<< VMware.Vim.OptionValue $option.key = $tgtkey $opti

on.value = $tgtvalue $optarr += $option

You cannot call a method on a null-valued expression.

At C:\boot-config\test.ps1:9 char:22

+ $optMgr.UpdateOptions( <<<< $optarr)

The test.ps1 is;

$tgtkey = "NFS.MaxVolumes"

$tgtvalue = 12

$h = "ukdc219110"

$esx = Get-View -ViewType HostSystem -Filter @{"Name" = $h} $optMgr = Get-View -Id $esx.ConfigManager.AdvancedOption

$optarr = @()

$option = New-Object VMware.Vim.OptionValue $option.key = $tgtkey $option.value = $tgtvalue $optarr += $option

$optMgr.UpdateOptions($optarr)

Any ideas?

Many thanks!!!

Sean.

IMPORTANT NOTICE

If you have received this e-mail in error or wish to read our e-mail disclaimer statement and monitoring policy, please refer to the statement below or contact the sender.

This communication is from Deloitte & Touche LLP. Deloitte & Touche LLP is a limited liability partnership registered in England and Wales with registered number OC303675 and its registered office at Stonecutter Court, 1 Stonecutter Street, London EC4A 4TR, United Kingdom. Deloitte & Touche LLP is authorised and regulated by the Financial Services Authority. Deloitte & Touche LLP is the United Kingdom member firm of Deloitte Touche Tohmatsu (‘DTT’), a Swiss Verein whose member firms are separate and independent legal entities. Neither DTT nor any of its member firms has any liability for each other’s acts or omissions. Services are provided by member firms or their subsidiaries and not by DTT.

This communication and any attachments contain information which is confidential and may also be privileged. It is for the exclusive use of the intended recipient(s). If you are not the intended recipient(s) please note that any form of disclosure, distribution, copying or use of this communication or the information in it or in any attachments is strictly prohibited and may be unlawful. If you have received this communication in error, please return it with the title "received in error" to IT.SECURITY.UK@deloitte.co.uk then delete the email and destroy any copies of it.

E-mail communications cannot be guaranteed to be secure or error free, as information could be intercepted, corrupted, amended, lost, destroyed, arrive late or incomplete, or contain viruses. We do not accept liability for any such matters or their consequences. Anyone who communicates with us by e-mail is taken to accept the risks in doing so. When addressed to our clients, any opinions or advice contained in this e-mail and any attachments are subject to the terms and conditions expressed in the governing Deloitte & Touche LLP client engagement letter.

Opinions, conclusions and other information in this e-mail and any attachments which do not relate to the official business of the firm are neither given nor endorsed by it.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

It looks as if you're missing the s in the script.

The Communities SW has problems when accessed with IE.

I attached the script to avoid this problem.

Does that work?

Some other points to note:

- you have be connected to the VC. Do a Connect-VIServer first

- use the latest version (build 103777)


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

0 Kudos
sddunne
Contributor
Contributor
Jump to solution

Fantastic!!! It worked a treat, thank you very much for your help!!!!

Have a great weekend!

Sean.

0 Kudos
sddunne
Contributor
Contributor
Jump to solution

Hi there,

Do you by any chance know how to change an advanced setting that uses a checkbox rather than a value? I'm trying to uncheck VMkernel.Boot.Force.36BitMTRRMask on a bunch of hosts?

Many thanks,

Sean.

0 Kudos
gallopa
Enthusiast
Enthusiast
Jump to solution

Hi Sean,

I don't know the answer to this with any certainty but have you tried assigning a value of 0 to the option?

Regards,

Andrew

0 Kudos
sddunne
Contributor
Contributor
Jump to solution

Hi Andrew,

Yep, tried 0, "0", 1 & "1" and no joy!

Cheers!

Sean.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The advanced settings that have a check box need Boolean values ($true or $false).

The Value property in the OptionValue object is defined as "xsd:anyType".

To pass the correct value type use one of the OptionType extensions.

In this case use the BoolOption type.

$tgtkey = "VMkernel.Boot.force36BitMTRRMask"
$tgtvalue = $FALSE

$esx = Get-View -ViewType HostSystem -Filter @{"Name" = <ESX-server>}
$optMgr = Get-View -Id $esx.ConfigManager.AdvancedOption
 
$optarr = @()
$option = New-Object VMware.Vim.OptionValue
$option.key = $tgtkey
$option.Value = New-Object VMware.Vim.BoolOption
$option.value = $tgtvalue
$optarr += $option
$optMgr.UpdateOptions($optarr)

PS: I would advise to start new discussions in the community for new questions/subjects.

That makes it easier for others to follow.


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

0 Kudos
richard_judd
Contributor
Contributor
Jump to solution

Does anyone know how to convert the powershell code below in to vb.net.. i've tried but must be missing something? I've highlighted the line i'm having trouble with in RED

&lt;start PS Snip

$info = new-object vmware.vim.VirtualMachineConfigSpec

$info.extraconfig += new-object VMware.Vim.OptionalValue

$info.extraconfig[0].key="numDisplays"

$info.extraconfig[0].value = "2"

end PS Snip&gt;

&lt;start vbSnip

Dim info as VMware.Vim.VirtualMachineConfigSpec

info = new VMware.vim.VirtualMachineConfigSpec

with info

.numCPUs = "2"

.MemoryMB = "1024"

.extraConfig += New VMware.Vim.OptionValue

.extraConfig(0).key = "numDisplays"

.extraConfig(0).value = "2"

end with

End vbSnip&gt;

0 Kudos
harkamal
Expert
Expert
Jump to solution

vb.net ? No offences, but there is sizable c#/powershell community to assist.

0 Kudos
richard_judd
Contributor
Contributor
Jump to solution

C

  1. is also fine ... i've looked but cant see anything on the specific settings i'm looking for

0 Kudos
bubbzie
Contributor
Contributor
Jump to solution

Hey LucD, what if you're doing this against multiple hosts, I tried this:

&lt;code&gt;$tgtkey = "NFS.MaxVolumes"<br /><br/>
$tgtvalue = 12<br/><br/>
$myHosts = get-vmhost|Select Name&lt;/code&gt;
&lt;code&gt;$esx = Get-View -ViewType HostSystem -Filter @{"Name" = &lt;/code&gt;&lt;code&gt;$myHosts&lt;/code&gt;&lt;code&gt;}<br /><br/>
$optMgr = Get-View -Id $esx.ConfigManager.AdvancedOption<br/><br/>
rest of code...&lt;/code&gt;

but I am getting following error:

&lt;-----  Invalid object specified for parameter Filter - 'Hashtable{String, VMHostImpl}'. Valid type is  'Hashtable{String, String}'.	<br /><br/>
At :line:6 char:21<br/><br/>
+ 	$hostView = Get-View &lt;&lt;&lt;&lt;  -ViewType HostSystem -Filter @{"Name" = $VMHosts } ----&gt;

I also tried this as well:

$myHosts = get-vmhost|select Name<br /><br/>
ForEach ($VMHosts in Get-VMHost){<br/><br/>
$hostView = Get-View -ViewType HostSystem -Filter @{"Name" = $VMHosts }

rest of code}

same error, thnx. <br /><br/>

0 Kudos
richard_judd
Contributor
Contributor
Jump to solution

sorted it ... Smiley Happy

Dim info As VMware.Vim.VirtualMachineConfigSpec info = New VMware.Vim.VirtualMachineConfigSpec With info numDisplaysKey = "Svga.numDisplays" numDisplaysValue = "2" .ExtraConfig = New OptionValue(0) {} .ExtraConfig(0) = New OptionValue() .ExtraConfig(0).Key = numDisplaysKey .ExtraConfig(0).Value = numDisplaysValue End With

0 Kudos