VMware Cloud Community
PaulB2
Enthusiast
Enthusiast

PowerCLI how to check/delete/zero a file size in /tmp ?

My ESXi 6.5 hosts /tmp folder is full with the HPE file "ams-bbUsg.txt" using all the space. Is there a way to use powercli to delete or zero the file if present?

Thanks

Tags (1)
8 Replies
LucD
Leadership
Leadership

There is no PowerCLI cmdlet to do that.
But you can use SSH (via the Posh-SSH module for example) to run commands in ESXi.


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

BBB36
Enthusiast
Enthusiast

Funny, I was actually also looking for this exact same thing, which is how I found this.

To follow through with LucD's comment, I made a very slight modification to his script from the one he provided in another thread here -> #https://communities.vmware.com/thread/605539.

I tested it on 2 hosts last night and it worked.

You'd have to install the Posh-SSH module first (Find-Module Posh-SSH | Install-Module), and all the root passwords must be the same if you're running it against multiple ESXi hosts.

As always, thanks LucD. I'm sure you know how many thousands of people's careers you've saved Smiley Happy.

============================Individual ESXi host============================

$esxName = 'esxi_host_name'

$cred = Get-Credential -Message 'Enter credentials'

$cmdsub = @'

> /tmp/ams-bbUsg.txt

'@

$esx = Get-VMHost -Name $esxName

$session = New-SSHSession -ComputerName $esx.Name -Credential $cred –AcceptKey

$result = Invoke-SSHCommand -SSHSession $session -Command $cmdSub

Remove-SSHSession -SSHSession $session | Out-Null

============================Multiple ESXi hosts============================

$esxName = Get-Content -Path "C:\Path\to\textfilewithhostnames.txt"

$cred = Get-Credential -Message 'Enter credentials'

foreach($esxNames in $esxName)

{

$cmdsub = @'

> /tmp/ams-bbUsg.txt

'@

$esx = Get-VMHost -Name $esxNames

$session = New-SSHSession -ComputerName $esx.Name -Credential $cred –AcceptKey

$result = Invoke-SSHCommand -SSHSession $session -Command $cmdSub

Remove-SSHSession -SSHSession $session | Out-Null

}

fourpixels
Enthusiast
Enthusiast

Hi BBB36,

I'm trying to use your script but for some reason the TMP was not getting deleted.

I've run your script and check on the Putty the TMP is still 100%.

0 Kudos
fourpixels
Enthusiast
Enthusiast

Hi BBB36

It just creating another same file

pastedImage_0.png

0 Kudos
LucD
Leadership
Leadership

Have you set UTF-8 as the default output in PowerShell?

That question mark at the end of the filename seems to indicate that.

Or have you used that question mark as a wild card character in the script?


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

0 Kudos
fourpixels
Enthusiast
Enthusiast

LucD

Hi thanks for response. I didn't modifying anything on the script I just copy it as is and run it.

So tried this version below and use the rm -rf command and it deletes the duplicate file with "?" but if I run it again original TMP still there.

$esxName = 'hostname'

$cred = Get-Credential -Message 'Enter credentials'

$cmdsub = @'

rm -rf /tmp/ams-bbUsg.txt

'@

$esx = Get-VMHost -Name $esxName

$session = New-SSHSession -ComputerName $esx.Name -Credential $cred –AcceptKey

$result = Invoke-SSHCommand -SSHSession $session -Command $cmdSub

Remove-SSHSession -SSHSession $session | Out-Null

Apologies, still learning the PowerShell hope you can help me.

0 Kudos
fourpixels
Enthusiast
Enthusiast

Was able to resolve it by using this one below

$cmdsub = "

> /tmp/ams-bbUsg.txt | out-string

"

0 Kudos
BBB36
Enthusiast
Enthusiast

As long as the HPE Agentless Management Service (AMS) version 11.4.0 is still installed, yes the file will get re-created (or the data will re-populate if you'd chosen to empty it instead).

You'd have to upgrade AMS version 11.4.5 for the issue to be permanently fixed. See https://support.hpe.com/hpesc/public/docDisplay?docLocale=en_US&docId=emr_na-a00076197en_us