Remove _deviceImage-0.iso From ESXi Datastore

What’s Issue?

Sometimes, we need to prepare a VM with specific OS and deploy it on another environment, so we have to export the VM as OVA or OVF file.

Because of installing OS, we need to mount ISO file on our machine and may be we forgot remove ISO file from CD-ROM before exporting VM.

Then if we import the OVF/OVA file to another server or environment, the ISO file will be copied to the target folder with other files.

The file will be renamed to “_deviceImage-0.iso”.

If we deployed one or two machine, there is no concern about free space on our datastore but think about 100 or more machine!

If each ISO used 3GB, we will lose more than 300GB for 100 VMs.

Solution

There is a simple solution for single machine, we can remove ISO file in the machine configuration and delete the file from the machine’s folder.

_deviceimage-0

But what is solution for more than one machine?

Here is a script that you can customize that for your environment and add some lines to get machine list from administrator. The script should be run via PowerCLI and we should connect PowerCLI console to a vCenter.

VMS=Get-Content -Path "File.txt"
ForEach ($VM in $VMS) {
    $DataCenter=Get-VM $VM | Get-DataCenter
    $DataStore=Get-VM $VM | Get-View | %{$_.Config.datastoreurl.name}
    $Folder=Get-VM $VM | Get-View | %{$_.Config.files.logdirectory.split("]")[1].TrimStart(" ")}
    $Path=$Datacenter.name+"/"+$Datastore + "/"+$Folder
    $File=$Path+"_deviceImage-0.iso"
    CD C:\
    CD vmstore:
    If (Test-Path $File) {
        Get-VM $VM | Get-CDDrive | Set-CDDrive -NoMedia -Confirm:$False
                #If you want to remove files automatically, remove -Confirm from the below line
        Remove-Item -Path $File -Confirm
        Write-Host "This file has been removed: $File"
        } Else {
        Write-Host "The file does not exist on this path: $Path"
        }
    }

Hope the script will help you to free your datastore and save your storage space.

Davoud Teimouri

Davoud Teimouri is as a professional blogger, vExpert 2015/2016/2017/2018/2019, VCA, MCITP. This blog is started with simple posts and now, it has large following readers.

Leave a Reply

Your email address will not be published. Required fields are marked *