VMware Cloud Community
paurgie
Contributor
Contributor

Alter hostd config via PowerCLI

This is a deep down setting, so I'd believe if it's not a thing you can do over powercli, but I figure it's worth a shot

We have issues where when we resize our NetApp datastores, it throws a space alarm every morning on a different datastore, which doesn't actually have a problem.  This is a real butterfly effect, but we know how to swat it.

If we go to each host and fix /etc/vmware/hostd/config.xml and change this value to 30 the problem goes away:

<config>

   <plugins>

      <hostsvc>

         <datastore>

            <refreshInterval>0</refreshInterval>

         <datastore>

      <hostsvc>

   <plugins>

<config>

The question is if there's a way to go tweak this setting via scripting, preferably powercli as I use a script to configure fresh hosts already.  I've done a fair amount of esxcli and Set-AdvancedSetting operations, but I didn't see a way to get to 'this' setting.

0 Kudos
4 Replies
LucD
Leadership
Leadership

Can you use SSH access to the ESXi nodes?


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

0 Kudos
LucD
Leadership
Leadership

If you can do a SSH session to the ESXi host and you have the Posh-SSH module installed, you can do something like this.

$esxName = 'esx.domain.com'

$user = 'root'

$pswd = 'VMware1!'

$esxPath = '/etc/vmware/hostd'

$esxFile = 'config.xml'

$localFile = "$($env:TEMP)\config.xml"

$xmlPath = 'config.plugins.hostsvc.datastore'

$nodeName = 'refreshInterval'

$nodeValue = 30


$secpswd = ConvertTo-SecureString -String $pswd -AsPlainText -Force

$cred = New-Object System.Management.Automation.PSCredential ($user,$secpswd)


# Copy original file as backup

$session = New-SSHSession -ComputerName $esxName -Credential $cred -AcceptKey

Invoke-SSHCommand -SessionId $session.SessionId -Command "cp $esxPath/$esxFile $esxPath/$($esxFile.Replace('config','config-orig2'))"

Remove-SSHSession -SessionId $session.SessionId


# Download config.xml

Get-SCPFile -ComputerName $esxName -Credential $cred -RemoteFile "$esxPath/$esxFile" -LocalFile $localFile -AcceptKey

$config = New-Object System.Xml.XmlDocument

$config.LoadXml((Get-Content -Path $localFile))

$ds = $config.config.plugins.hostsvc.datastore

if(-not $ds.Item($nodeName)){

   $child = $config.CreateElement($nodeName)

   $child.InnerText = $nodeValue

   $ds.AppendChild($child)

}

else{

   $ds.Item($nodeName).Innertext = $nodeValue

}

$config.Save($localFile)


# Convert from DOS to Unix

$text = Get-Content -Raw -Path $localFile

$text -replace "`r`n","`n" | Set-Content -Path $localFile


# Upload new config.xml

Set-SCPFile -ComputerName $esxName -Credential $cred -LocalFile $localFile -RemotePath $esxPath


# Cleanup

Remove-Item -Path $localFile -Confirm:$false


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

0 Kudos
paurgie
Contributor
Contributor

Well, that's an interesting take on it...  We do enable SSH just because we use it enough, but a truly crafty guy could just enable and disable it before and after this nugget.

I guess I could throw that into a function and hide it forever Smiley Wink

0 Kudos
LucD
Leadership
Leadership

Lol!

Btw, were you able to test it?

I only tested it on ESXi 6.7


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

0 Kudos