Skip to content
Switch branches/tags
Go to file
Cannot retrieve contributors at this time
# Author: Donovan Durand
# Website:
# Description: PowerCli script to increase the vsfwd memory on NSX prepared ESXi hosts
Connect-VIServer -Server -User root -Password supersecret
$cluster = Read-Host "Enter cluster name:"
$esxhosts = Get-Cluster $cluster | Get-VMHost
$esxcreds = Get-Credential
$datastore = "<datastore_name>"
foreach ($esx in $esxhosts){
Write-host "Connecting to:" $esx
$ssh = Posh-SSH\New-SSHSession -ComputerName $esx -Credential $esxcreds -AcceptKey:$true
Write-host "SSH connection established to:" $esx -ForegroundColor Green
Write-host "Stopping vShield-Stateful-Firewall service" -ForegroundColor Green
Invoke-SSHCommand -SSHSession $ssh -Command (" /etc/init.d/vShield-Stateful-Firewall stop")
Write-host "Backup original vShield-Stateful-Firewall config file" -ForegroundColor Green
Invoke-SSHCommand -SSHSession $ssh -Command (" cp /etc/init.d/vShield-Stateful-Firewall /etc/init.d/vShield-Stateful-Firewall.orig")
Write-host "Copying file to /tmp" -ForegroundColor Green
Invoke-SSHCommand -SSHSession $ssh -Command (" cp /etc/init.d/vShield-Stateful-Firewall /tmp/")
Write-host "Changing vsfwd memory to 512mb" -ForegroundColor Green
Invoke-SSHCommand -SSHSession $ssh -Command (" sed -i '/MEMSIZE/s/256/512/' /tmp/vShield-Stateful-Firewall")
Write-host "Copying file to datastore" -ForegroundColor Green
Invoke-SSHCommand -SSHSession $ssh -Command (" cp /tmp/vShield-Stateful-Firewall /vmfs/volumes/$datastore/")
Write-host "Starting vShield-Stateful-Firewall service from the /tmp folder" -ForegroundColor Green
Invoke-SSHCommand -SSHSession $ssh -Command (" /tmp/vShield-Stateful-Firewall start")
Start-Sleep -s 10
Write-host "Check if vsfwd is running" -ForegroundColor Green
$service_stat = Invoke-SSHCommand -SSHSession $ssh -Command (" /tmp/vShield-Stateful-Firewall status")
write-host $service_stat.output
Write-host "Editing to make this change persistent on reboot." -ForegroundColor Green
Invoke-SSHCommand -SSHSession $ssh -Command ("sed -i '/exit/i cp /vmfs/volumes/$datastore/vShield-Stateful-Firewall /tmp/' /etc/rc.local.d/
Invoke-SSHCommand -SSHSession $ssh -Command ("sed -i '/exit/i /tmp/vShield-Stateful-Status restart’ /etc/rc.local.d/
Write-host "Validating vsfwd memory config" -ForegroundColor Green
$return = Invoke-SSHCommand -SSHSession $ssh -Command ("vsish -e set /sched/groupPathNameToID host vim vmvisor vsfwd")
$groupid = $return.output[0].ToString().Trim()
Write-Host "vsfwd group id:" $groupid
$return1 = Invoke-SSHCommand -SSHSession $ssh -Command ("vsish -e get /sched/groups/$groupid/memAllocationInMB")
Remove-SSHSession -SSHSession $ssh