hi there,
we having a problem with phantom snapshots filling up our lun's
is there a script out there to search throught the datastores to find these files?
the manual way is listed here - http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=100231...
thank you
Oops, it looks as if something went wrong during the copy/paste of the script.
This should be the correct version
foreach($vm in Get-VM){ $vm | Get-HardDisk | %{ if($_.Filename -notlike "*-??????.vmdk"){ $dsName = $_.Filename.Split(']')[0].TrimStart('[') $folder = $_.Filename.Split('/')')[1].TrimStart(' ') New-PSDrive -Name 'ds' -Location (Get-Datastore $dsName) -PSProvider VimDatastore -Root '\' -Confirm:$false | Out-Null Get-ChildItem -Path ("ds:\" + $folder) -Recurse | where{$_.ItemType -ne "Folder"} | %{ if($_.Name -like "*-??????.vmdk"){ Write-Host "VMname:" $vm.Name "`tFile:" $_.Name } } Remove-PSDrive -Name 'ds' -Confirm:$false } } }
And to make sure the forum SW doesn't mess with the square brackets, I have attached the script as well.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I hope I understood your question (and the KB) correctly.
The following script will look at all guests and check the hard disks for each of them.
If there is no snapshot on the guest, the script will search the guest's folder for any -00000X.vmdk type files.
The script accesses the guest's files through the datastore provider (which may not be the fastest way to do this).
foreach($vm in Get-VM){ $vm | Get-HardDisk | %{ if($_.Filename -notlike "*-??????.vmdk"){ $dsName = $_.Filename.Split(']')[0].TrimStart('[') $folder = $_.Filename.Split('/')')[1].TrimStart(' ') New-PSDrive -Name 'ds' -Location (Get-Datastore $dsName) -PSProvider VimDatastore -Root '\' -Confirm:$false | Out-Null Get-ChildItem -Path ("ds:\" + $folder) -Recurse | where{$_.ItemType -ne "Folder"} | %{ if($_.Name -like "*-??????.vmdk"){ Write-Host "VMname:" $vm.Name "`tFile:" $_.Name } } Remove-PSDrive -Name 'ds' -Confirm:$false } } }
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
hi there,
im looking for the *delta.vmdk files in all the datastores
when i run this script i get this error
PS D:\Users\william\Desktop> & '.\delta files.ps1'
Unexpected token ')[1].TrimStart(' in expression or statement.
At D:\Users\william\Desktop\delta files.ps1:5 char:53
+ $folder = $_.Filename.Split('/')')[1].TrimStart(' <<<< ')
+ CategoryInfo : ParserError: ()[1].TrimStart(:String) [], ParseException
+ FullyQualifiedErrorId : UnexpectedToken
Oops, it looks as if something went wrong during the copy/paste of the script.
This should be the correct version
foreach($vm in Get-VM){ $vm | Get-HardDisk | %{ if($_.Filename -notlike "*-??????.vmdk"){ $dsName = $_.Filename.Split(']')[0].TrimStart('[') $folder = $_.Filename.Split('/')')[1].TrimStart(' ') New-PSDrive -Name 'ds' -Location (Get-Datastore $dsName) -PSProvider VimDatastore -Root '\' -Confirm:$false | Out-Null Get-ChildItem -Path ("ds:\" + $folder) -Recurse | where{$_.ItemType -ne "Folder"} | %{ if($_.Name -like "*-??????.vmdk"){ Write-Host "VMname:" $vm.Name "`tFile:" $_.Name } } Remove-PSDrive -Name 'ds' -Confirm:$false } } }
And to make sure the forum SW doesn't mess with the square brackets, I have attached the script as well.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I know this is an old post but can you help me out with the script
i keep getting this error in one of my datacentres.
I think i may have something wromg with my VC as it works fine in another lab.
That looks indeed is if there is a problem with the file structure on that datastore.
Can you check with the datastore browser from the vSphere client if the folder exists and if you descend into that folder ?
Try replacing
Get-ChildItem -Path ("ds:\" + $folder) -Recurse
with
Get-ChildItem -Path ("ds:\" + $folder) -Recurse -ErrorAction SilentlyContinue
that way the script should at least continue after the faulty folder/file
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Luc,
Within our large environment we lose LUN space to what we call 'Phantom Disks' .. where a team removes a virtual machine but the VMDK files are left behind.
Is there a way to alter this script to deal with these VMDK 'phantoms'..?
Hoping, - John M.
You could try my Spring Cleaning script.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hey Luc,
I ran the following script which seems to work ok, yes its a bit slow but what I was really looking for was to scan through all my datastores and find any file with -??????.vmdk even if its not orphaned and it in use. Can you tell me if there is any faster way of doing this?
foreach($vm in Get-VM){ $vm | Get-HardDisk | %{ if($_.Filename -notlike "*-??????.vmdk"){ $dsName = $_.Filename.Split(']')[0].TrimStart('[') $folder = $_.Filename.Split('/')[0].Split(']')[1].TrimStart(' ') New-PSDrive -Name 'ds' -Location (Get-Datastore $dsName) -PSProvider VimDatastore -Root '\' -Confirm:$false | Out-Null Get-ChildItem -Path ("ds:\" + $folder) -Recurse -ErrorAction SilentlyContinue | where{$_.ItemType -ne "Folder"} | %{ if($_.Name -like "*-??????.vmdk"){ Write-Host "VMname:" $vm.Name "`tFile:" $_.Name } } Remove-PSDrive -Name 'ds' -Confirm:$false } } }
You could make a table with all the VMDK files from the registered VMs and then search all datastores for VMDK files.
The ones that are not in the table most probably are phantom VMDKs.
That's in fact what my script I mentioned earlier is doing.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Luc, Do you have a simple script that searches datastores for anyfile with -0?????.vmdk I think the script I used above is a little more complex in that it searches for only orphanhed delta files, I would like to search for all, I have some instances where our backup system deletes the snapshot but for some reason it only removes it for the snapshot manager, I then have to consolidate the disks to resolve the issue?
Thanks Luc, that spring cleaning script is very useful!
I've also found our backup system fails to remove snapshots sometimes but instead of leaving the vmdk files it removes the snapshot from the snapshot manager (Or leaves the Consolidate Helper) but the VM guest is still referencing the snapshot vmdk files.
Unfortunately your script fails to identify these since those files are still in use.
I wrote a simple script to quickly identify the particular guests which may be afflicted by this issue so we can check them regularly:
foreach($vm in Get-VM)
{
$vm | Get-HardDisk | %{
if ($_.Filename -like "*-??????.vmdk")
{
if (!(Get-Snapshot $vm))
{
Write-Host "Missing snapshot image for:" $vm.Name "on host:" $vm.Host
Continue
}
elseif (Get-Snapshot $vm | where{$_.Name -like "Consolidate*"})
{
if (@(Get-Snapshot $vm).Length -eq 1)
{
Write-Host "Consolidate Helper snapshot only for:" $vm.Name "on host:" $vm.Host
Continue
} else {
Write-Host "Consolidate Helper snapshot plus others for:" $vm.Name "on host:" $vm.Host
Continue
}
}
else
{
Continue
}
}
}
}
Awesome script but I use RVTools to do the same thing. The problem we are having with our backup tool and vmware snapshots is that even after the snapshot is missing in snapshot manager, the snapshots are not marked as consolidated helper files or orphaned files. We had a virtual machine with over 30 snapshot vmdks that were all valid but did not show up on any searchable format. The only way we were able to find them is by using this command on the first host in each cluster. Anyway someone could make this into a script to run accross all datastores in a Virtual Center?
find /vmfs/volumes/ -name *0000*.* -print