Hi,
Is there a way to disable system swap setting on each esxi in vCenter Server.
i can do one by one using Esxi-->Configure-->System swap. But how to do for all in cluster.
i can only see option to find where it is active.
foreach($esx in Get-VMHost){
$esxcli = Get-EsxCli -VMHost $esx
$esxcli.sched.swap.system.get() | Select @{N='VMHost';E={$esx.Name}},HostLocalSwapActive
}
not much of use.
If you can use the SSH service on each ESXi node and if you have the Posh-SSH module installed, you could do
$user = 'root'
$pswd = 'VMware1!'
$cmd = 'services.sh restart'
$cred = New-Object -TypeName PSCredential -ArgumentList $user,(ConvertTo-SecureString -String $pswd -AsPlainText -Force)
Get-Cluster -Name $clusterName |
Get-VMHost |
ForEach-Object -Process {
$esxcli = Get-EsxCli -VMHost $_ -V2
$swap = @{
datastoreenabled= $false
hostcacheenabled = $false
hostlocalswapenabled = $false
}
$esxcli.sched.swap.system.set.Invoke($swap) |
Select @{N='VMHost';E={$esxcli.VMHost.Name}},
@{N='Swap Change Success';E={$_}},
@{N='Service Restart Exit Status';E={
$oldState = Get-VMHostService -VMHost $esxcli.VMHost.Name | where{$_.Key -eq 'TSM-SSH'}
if(-not $oldState.Running){
Start-VMHostService -HostService $oldState -Confirm:$false
}
$session = New-SSHSession -ComputerName $esxcli.VMHost.Name -Credential $cred –AcceptKey -ConnectionTimeout 15
$result = Invoke-SSHCommand -SSHSession $session -Command $cmd
Remove-SSHSession -SSHSession $session | Out-Null
if(-not $oldState.Running){
Stop-VMHostService -HostService $oldState -Confirm:$false
}
$result.ExitStatus
}}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Did you try like this?
Get-Cluster -Name $clusterName |
Get-VMHost |
ForEach-Object -Process {
$esxcli = Get-EsxCli -VMHost $_ -V2
$swap = @{
datastoreenabled= $false
hostcacheenabled = $false
hostlocalswapenabled = $false
}
$esxcli.sched.swap.system.set.Invoke($swap)
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
sure let me give this a try...
Regards
Hi,
It worked , getting output like below , and setting is disabled on cluster
true
true
true
true
true
true
true
true
true
is there way to give details like hostname and on which host its true and on which it was not applicable.
lastly is there single liner to restart services.sh on all host. after above is done.
If you can use the SSH service on each ESXi node and if you have the Posh-SSH module installed, you could do
$user = 'root'
$pswd = 'VMware1!'
$cmd = 'services.sh restart'
$cred = New-Object -TypeName PSCredential -ArgumentList $user,(ConvertTo-SecureString -String $pswd -AsPlainText -Force)
Get-Cluster -Name $clusterName |
Get-VMHost |
ForEach-Object -Process {
$esxcli = Get-EsxCli -VMHost $_ -V2
$swap = @{
datastoreenabled= $false
hostcacheenabled = $false
hostlocalswapenabled = $false
}
$esxcli.sched.swap.system.set.Invoke($swap) |
Select @{N='VMHost';E={$esxcli.VMHost.Name}},
@{N='Swap Change Success';E={$_}},
@{N='Service Restart Exit Status';E={
$oldState = Get-VMHostService -VMHost $esxcli.VMHost.Name | where{$_.Key -eq 'TSM-SSH'}
if(-not $oldState.Running){
Start-VMHostService -HostService $oldState -Confirm:$false
}
$session = New-SSHSession -ComputerName $esxcli.VMHost.Name -Credential $cred –AcceptKey -ConnectionTimeout 15
$result = Invoke-SSHCommand -SSHSession $session -Command $cmd
Remove-SSHSession -SSHSession $session | Out-Null
if(-not $oldState.Running){
Stop-VMHostService -HostService $oldState -Confirm:$false
}
$result.ExitStatus
}}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
awsome , let me run this and get back to you
Thanks alot
thanks for all your help. Worked like charm.
Not sure after services.sh ideally it should disconnect and reconnect host but didn't do it this time. Wonder if it is actually restarting service.
You could check in the /var/log/ jumpstart-stdout.log
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference