VMware Cloud Community
dborgill
Enthusiast
Enthusiast
Jump to solution

URGENT: PowerCLI Script to Redirect /var/core to External Datastore

Long story short, stateless auto deploy environment, 150+ hosts, hostd is crashing and filling up /var/core on the local partition. VMware support has instructed us to redirect /var/core directory to an external datastore. So..

1 - I have already created all the directories (ie /vmfs/volumes/datastore/coredumps/hostname)

2 - I need to see if I can script this for each host:

rm /var/core

ln -s /vmfs/volumes/datastore/coredumps/hostname /var/core

Also, if I have to do this manually, last resort, is there a way to script enabling SSH on all hosts?

Thanks in advance

Reply
0 Kudos
1 Solution

Accepted Solutions
Zsoldier
Expert
Expert
Jump to solution

Install-Module Posh-SSH                             

Import-Module Posh-SSH

$ESXiRootCreds = Get-Credential

$VMHosts = Get-VMHost

Foreach ($VMHost in $VMHosts){

   $VMHost | Get-VMHostService | Where {$_.Key -eq "TSM-SSH"} | Start-VMHostService -confirm:$False

New-SSHSession -computername $VMHost.Name -Credential $ESXiRootCreds

Invoke-SSHCommand -SessionId 0 -Command "rm /var/core"

Invoke-SSHCommand -SessionId 0 -Command "ln -s /vmfs/volumes/datastore/coredumps/$($VMHost.Name) /var/core"

Invoke-SSHCommand -SessionId 0 -Command "logout"

Remove-SSHSession 0

$VMHost | Get-VMHostService | Where {$_.Key -eq "TSM-SSH"} | Stop-VMHostService -confirm:$False

}

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier

View solution in original post

Reply
0 Kudos
1 Reply
Zsoldier
Expert
Expert
Jump to solution

Install-Module Posh-SSH                             

Import-Module Posh-SSH

$ESXiRootCreds = Get-Credential

$VMHosts = Get-VMHost

Foreach ($VMHost in $VMHosts){

   $VMHost | Get-VMHostService | Where {$_.Key -eq "TSM-SSH"} | Start-VMHostService -confirm:$False

New-SSHSession -computername $VMHost.Name -Credential $ESXiRootCreds

Invoke-SSHCommand -SessionId 0 -Command "rm /var/core"

Invoke-SSHCommand -SessionId 0 -Command "ln -s /vmfs/volumes/datastore/coredumps/$($VMHost.Name) /var/core"

Invoke-SSHCommand -SessionId 0 -Command "logout"

Remove-SSHSession 0

$VMHost | Get-VMHostService | Where {$_.Key -eq "TSM-SSH"} | Stop-VMHostService -confirm:$False

}

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier
Reply
0 Kudos