
Automate ISO File Deletion from VMware vCenter Datastores Using PowerShell
Feb 11
2 min read
0
48
0
In a VMware vCenter environment, managing ISO files across multiple datastores can be a cumbersome task. If you have numerous ISO files that need to be deleted, doing it manually is time-consuming and prone to errors. Thankfully, PowerShell, combined with VMware PowerCLI, can automate this process efficiently.
Prerequisites:
Before running the script, ensure you have "VMware PowerCLI" installed, if not then below is the command line to install it.
# Install-Module -Name VMware.PowerCLI -Scope CurrentUser
A Quick Screenshots of Existing ISO Files Across Datastores:
As you can see in below screenshot, I have five ISO files across two datastores for deletion. On, how to retrieve ISO files info, please refere to this blog post.
Automate "ISO" File Retrieval from VMware vCenter Datastores Using PowerShell

PowerShell Script & Procedure:
The script below connects to your vCenter server, searches through all datastores for .iso files, and deletes them.
Please note, the -WhatIf and -Confirm parameters can be used based on your wish/requirement to preview actions and get confirmation before proceeding.
Connect to you vCenter Server.
# Connect-VIServer -Server $vcenterServer -User $vcUser -Password $vcPassword
The script below connects to your vCenter server, searches through all datastores for .iso files, and deletes them (Please note, as stated above the -WhatIf and -Confirm parameters can be used to preview the action before proceeding). In this below script I've used -Confirm switch.
# Get all datastores
$datastores = Get-Datastore
foreach ($datastore in $datastores) {
# Get all ISO files in the datastore
$isoFiles = Get-ChildItem -Path $datastore.DatastoreBrowserPath -Recurse -Include *.iso
foreach ($isoFile in $isoFiles) {
# Delete the ISO file
Remove-Item -Path $isoFile.FullName -Confirm:$true
}
}
Disconnect-VIServer -Server vc-l-01a.corp.local -Confirm:$false
Run the above PowerShell script now to perform all the ISO files deletion from the vCenter now. I've selected A (Yes to All), you can pick the option based on your situation and need.
Note - Please be patient, as it needs to check through all the datastores & perform deletion so it may take some time.
Now, you can verify the deletion tasks from the vCenter Recent tasks view as well.
!Happy Scripting!
Further Reference:
Automate "ISO" File Retrieval from VMware vCenter Datastores Using PowerShell