VMware Cloud Community
mark_chuman
Hot Shot
Hot Shot

vCenter Temporary File Clean Up Script

Hope this comes in handy for someone.  Use at your own risk.

This will only work on windows based VCs and you'll have to enable remote powershell as outlined here - How to Run PowerShell Commands on Remote Computers

Unzip the attached file to a folder, run the disk_clean.ps1 from powercli.

Script contents:

$ErrorActionPreference = "SilentlyContinue"

$vcservers = Import-Csv ".\vcenters.csv"

$VCCred = Get-Credential

Write-Host " "

foreach ($vc in $vcservers) {

Write-Host "Cleaning up files (VC support bundles, dmp files in vcenter log location, all files in c:\temp and other dmp files created by vCenter) in -"$vc.name

Invoke-Command -ComputerName $vc.name `

-ScriptBlock {

#Remove any vCenter support files from user desktops

Get-ChildItem -recurse "C:\Users\*\Desktop" | Where-Object {$_.name -like "*vcsupport*"} | foreach ($_) {remove-item $_.fullname}

#Remove any dmp files from vCenter log location

Get-ChildItem "C:\ProgramData\VMware\VMware VirtualCenter\Logs" | Where-Object {$_.name -like "*.dmp"} | foreach ($_) {remove-item $_.fullname}

#Remove files from temp folder on C drive

Get-ChildItem -recurse "C:\Temp" | foreach ($_) {remove-item $_.fullname -recurse -force} -Confirm:$false

#Remove any dmp files created by vCenter

Get-ChildItem "C:\Windows\System32\config\systemprofile\AppData\Local\CrashDumps" | Where-Object {$_.name -like "vmdird.exe.*.dmp"} | foreach ($_) {remove-item $_.fullname}

} -credential $VCCred

}

Write-Host " "

0 Kudos
0 Replies