Hi,
Changing an existing advanced-setting is no problem, but setting a new one is a bit challenging.
PS C:\> get-vmhost esxihost.fqdn | Get-AdvancedSetting -Name "/Net/TcpipHeapSize"| Set-AdvancedSetting -Value 32 -Confirm:$false
Get-AdvancedSetting : 16.09.2021 07:38:35 Get-AdvancedSetting "/Net/TcpipHeapSize" option doesn't exist.
At line:1 char:35
+ ... 5.helsemn.no | Get-AdvancedSetting -Name "/Net/TcpipHeapSize"| Set-Ad ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-AdvancedSetting], InvalidName
+ FullyQualifiedErrorId : Client20_SystemManagementServiceImpl_ConvertToHashtable_OptionNotFound,VMware.VimAutomat
ion.ViCore.Cmdlets.Commands.GetAdvancedSetting
PS C:\> get-vmhost esxihost.fqdn | Set-AdvancedSetting -AdvancedSetting "/Net/TcpipHeapSize" -value 32
Set-AdvancedSetting : Cannot bind parameter 'AdvancedSetting'. Cannot convert the "/Net/TcpipHeapSize" value of type "S
ystem.String" to type "VMware.VimAutomation.ViCore.Types.V1.AdvancedSetting".
At line:1 char:72
+ ... o | Set-AdvancedSetting -AdvancedSetting "/Net/TcpipHeapSize" -value ...
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-AdvancedSetting], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomation.ViCore.Cmdlets.Commands.SetAdvancedS
etting
Any ideas how this could be solved?
Lars
Strange, I didn't realise that.
On the other hand, Set-VMHostAdvancedConfiguration says it is deprecated and to use Set-AdvancedSetting.
That would mean the only valid alternatie is to use Get-EsxCli, and the $esxcli.system.settings.advanced.set.Invoke(@{....}) command
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Shouldn't you be using New-AdvancedSetting for that?
I normally would use a Try-Catch
@larstr wrote:
Hi,
Changing an existing advanced-setting is no problem, but setting a new one is a bit challenging.
PS C:\> get-vmhost esxihost.fqdn | Get-AdvancedSetting -Name "/Net/TcpipHeapSize"| Set-AdvancedSetting -Value 32 -Confirm:$false Get-AdvancedSetting : 16.09.2021 07:38:35 Get-AdvancedSetting "/Net/TcpipHeapSize" option doesn't exist. At line:1 char:35 + ... 5.helsemn.no | Get-AdvancedSetting -Name "/Net/TcpipHeapSize"| Set-Ad ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-AdvancedSetting], InvalidName + FullyQualifiedErrorId : Client20_SystemManagementServiceImpl_ConvertToHashtable_OptionNotFound,VMware.VimAutomat ion.ViCore.Cmdlets.Commands.GetAdvancedSetting PS C:\> get-vmhost esxihost.fqdn | Set-AdvancedSetting -AdvancedSetting "/Net/TcpipHeapSize" -value 32 Set-AdvancedSetting : Cannot bind parameter 'AdvancedSetting'. Cannot convert the "/Net/TcpipHeapSize" value of type "S ystem.String" to type "VMware.VimAutomation.ViCore.Types.V1.AdvancedSetting". At line:1 char:72 + ... o | Set-AdvancedSetting -AdvancedSetting "/Net/TcpipHeapSize" -value ... + ~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Set-AdvancedSetting], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomation.ViCore.Cmdlets.Commands.SetAdvancedS etting
Any ideas how this could be solved?
Lars
$esx = Get-VMHost -Name esxihost.fqdn
Try{
Get-AdvancedSetting -Entity $esx -Name '/Net/TcpipHeapSize' -ErrorAction Stop |
Set-AdvancedSetting ...
}
Catch{
New-AdvancedSetting -Entity $esx ....
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It says it's not supported.
PS C:\> get-vmhost esxihost.fqdn | new-AdvancedSetting -Name "/Net/TcpipHeapSize" -value 32
Perform operation?
Creating advanced setting '/Net/TcpipHeapSize' on entity 'esxihost.fqdn'.
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): Y
new-AdvancedSetting : 16.09.2021 09:00:40 New-AdvancedSetting VMHosts do not support adding new advanced settings
At line:1 char:35
+ ... fqdn | new-AdvancedSetting -Name "/Net/TcpipHeapSize" -value 32 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (esxihost.fqdn:VMHostImpl) [New-AdvancedSetting], ViError
+ FullyQualifiedErrorId : Client20_SystemManagementServiceImpl_NewAdvancedSetting_NotSupportedOnVMHost,VMware.VimA
utomation.ViCore.Cmdlets.Commands.NewAdvancedSetting
Strange, I didn't realise that.
On the other hand, Set-VMHostAdvancedConfiguration says it is deprecated and to use Set-AdvancedSetting.
That would mean the only valid alternatie is to use Get-EsxCli, and the $esxcli.system.settings.advanced.set.Invoke(@{....}) command
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you Luc!
I ended up with the following:
param (
[string]$clustername = $( Read-Host "Enter clustername: " )
)
function Advanced-vmhostset{
$esxihost = get-vmhost $args[0]
$options= $args[1]
$value= $args[2]
Try{
Get-AdvancedSetting -Entity $esxihost -Name $options -ErrorAction Stop |
Set-AdvancedSetting -Value $value -Confirm:$false
}
Catch {
$vmhost=get-vmhost $esxihost
$esxcli = Get-EsxCli -VMHost $vmhost -V2
$opt= $esxcli.system.settings.advanced.set.CreateArgs()
$opt.option = $options
$opt.intvalue = $value
$esxcli.system.settings.advanced.set.Invoke($opt)
}
}
$hosts=get-cluster $clustername|get-vmhost
foreach($esxihost in $hosts){
Advanced-vmhostset $esxihost "/Net/TcpipHeapSize" 32
}
Lars