Hi All,
I am planning to delete the Orphaned/Zombie file and after looking through the vSphere platform, it has come to light that there are THOUSANDS (well over 10,000) of orphaned VMDK files, looks like this is not easy to delete. Is it possible to check the last modified date for Orphaned file ?
Thanks
Nvmk2014
Thanks André, that could indeed be the cause (Import-CSV has issues with importing UTF-8 files that do not have a BOM.
A possible bypass could be doing it this way (Get-Content does this correctly).
$file = 'C:\RVTools_tabvHealth.csv'
$driveName = 'DS'
$report = @()
# Cleanup leftovers
Get-PSDrive -Name $driveName -ErrorAction SilentlyContinue | Remove-PSDrive -Confirm:$False -ErrorAction SilentlyContinue
Get-Content -Path $file | ConvertFrom-Csv | where{$_.Message -match 'Possibly a Zombie vmdk file'} |
Group-Object -Property {$_.Name.Split(']')[0].Trimstart('[')} | %{
$ds = Get-Datastore -Name $_.Name
Try{
New-PSDrive -Name $driveName -PSProvider VimDatastore -Root \ -Location $ds > $null
}
Catch{
Write-Host "Could not create PSDrive for $($ds.Name)"
break
}
$_.Group | %{
$vmdkPath = "$($driveName)😕$($_.Name.Split(' ')[1])"
if(Test-Path -Path $vmdkPath){
$report += (Get-ChildItem -Path $vmdkPath | Select DatastoreFullPath,LastWriteTime)
}
else{
Write-Host "VMDK $($vmdkPath) not found"
}
}
Remove-PSDrive -Name DS -ErrorAction SilentlyContinue
}
#$report | Export-Csv report.csv -NoTypeInformation -UseCulture
$report
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Depends a bit on how you created your list of orphaned VMDK.
The SearchDatastoreSubFolders method allows to specify that the Modification property is returned.
The Datastore Provider also returns a LastWriteTime property.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD for your prompt response. We are using RV Tools for generating the Zombie/Orphaned file report. We want to validate with timestamp logs for deleting the orphaned file.
We will copy the orphaned vmdk file to temp dir and after time stamp validation we will delete the orphande vmdk file. Let me know if we can find out the time stamp of a orphaned vmdk file using the RV Tools report ?
thanks
vmk2014
If you save the result of the Health Check as a CSV, you can do the following to get the Last Write Time
$file = 'C:\RVTools_tabvHealth.csv'
Import-Csv -Path $file -UseCulture | where{$_.Message -match 'Possibly a Zombie vmdk file'} |
Group-Object -Property {$_.Name.Split(']')[0].Trimstart('[')} | %{
$ds = Get-Datastore -Name $_.Name
New-PSDrive -Name DS -PSProvider VimDatastore -Root \ -Location $ds > $null
$_.Group | %{
Get-ChildItem -Path "DS:\$($_.Name.Split(' ')[1])" | Select DatastoreFullPath,LastWriteTime
}
Remove-PSDrive -Name DS
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That's because a ForEach loop doesn't place anything in the pipeline.
If you want to save to a CSV you could do.
$file = 'C:\RVTools_tabvHealth.csv'
$report = @()
Import-Csv -Path $file -UseCulture | where{$_.Message -match 'Possibly a Zombie vmdk file'} |
Group-Object -Property {$_.Name.Split(']')[0].Trimstart('[')} | %{
$ds = Get-Datastore -Name $_.Name
New-PSDrive -Name DS -PSProvider VimDatastore -Root \ -Location $ds > $null
$_.Group | %{
$report += (Get-ChildItem -Path "DS:\$($_.Name.Split(' ')[1])" | Select DatastoreFullPath,LastWriteTime)
}
Remove-PSDrive -Name DS
}
$report | Export-Csv report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
How do the entries in the CSV file for potential orphaned files look?
I have them something like this
Name;Message;vCenter UUID
[datastore] folder/vmname_1.vmdk;Possibly a Zombie vmdk file! Please check.;4BC0B284-A3DB-4D75-A2E3-E070D4AEF2B1
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I made a somewhat more robust version of the script, give that one a try
$file = 'C:\RVTools_tabvHealth.csv'
$driveName = 'DS'
$report = @()
# Cleanup leftovers
Get-PSDrive -Name $driveName -ErrorAction SilentlyContinue | Remove-PSDrive -Confirm:$False -ErrorAction SilentlyContinue
Import-Csv -Path $file -UseCulture | where{$_.Message -match 'Possibly a Zombie vmdk file'} |
Group-Object -Property {$_.Name.Split(']')[0].Trimstart('[')} | %{
$ds = Get-Datastore -Name $_.Name
Try{
New-PSDrive -Name $driveName -PSProvider VimDatastore -Root \ -Location $ds > $null
}
Catch{
Write-Host "Could not create PSDrive for $($ds.Name)"
break
}
$_.Group | %{
$vmdkPath = "$($driveName)😕$($_.Name.Split(' ')[1])"
if(Test-Path -Path $vmdkPath){
$report += (Get-ChildItem -Path $vmdkPath | Select DatastoreFullPath,LastWriteTime)
}
else{
Write-Host "VMDK $($vmdkPath) not found"
}
}
Remove-PSDrive -Name DS -ErrorAction SilentlyContinue
}
$report | Export-Csv report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
No this again different error . PFA.
VMDK DS:\DCDDALPAPP1002/DCDDALPAPP1002.vmdk not found
Get-Datastore : 8/5/2016 9:50:44 AM Get-Datastore Datastore with
name '3026?EBS-1-XIO_LUN_153' was not found using the specified filter(s).
At C:\temp\Time-Stamp.ps1:10 char:11
+ $ds = Get-Datastore -Name $_.Name
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-Datastore], VimExceptio
n
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimA
utomation.ViCore.Cmdlets.Commands.GetDatastore
Could not create PSDrive for..
thanks
vmk2014
LucD,
Entries looks like this.
[VNX1_P4_Journal_LUN_4] 3029POC/zombi-3029POC_1.vmdk | Possibly a Zombie vmdk file! Please check. | b4dd9b40-0cee-4a54-8244-5b5806ac210a |
[VNX1_P4_Journal_LUN_4] 3029POC/zombi-3029POC_5.vmdk | Possibly a Zombie vmdk file! Please check. | b4dd9b40-0cee-4a54-8244-5b5806ac210a |
[VNX1_P4_Journal_LUN_4] 3029POC/zombi-3029POC_35.vmdk | Possibly a Zombie vmdk file! Please check. | b4dd9b40-0cee-4a54-8244-5b5806ac210a |
[VNX1_P4_Journal_LUN_4] 3029POC/zombi-3029POC_31.vmdk | Possibly a Zombie vmdk file! Please check. | b4dd9b40-0cee-4a54-8244-5b5806ac210a |
[VNX1_P4_Journal_LUN_4] 3029POC/zombi-3029POC_39.vmdk | Possibly a Zombie vmdk file! Please check. | b4dd9b40-0cee-4a54-8244-5b5806ac210a |
[VNX1_P4_Journal_LUN_4] 3029POC/zombi-3029POC_45.vmdk | Possibly a Zombie vmdk file! Please check. | b4dd9b40-0cee-4a54-8244-5b5806ac210a |
[VNX1_P4_Journal_LUN_4] 3029POC/zombi-3029POC_41.vmdk | Possibly a Zombie vmdk file! Please check. | b4dd9b40-0cee-4a54-8244-5b5806ac210a |
[VNX1_P4_Journal_LUN_4] 3029POC/zomvi-3029POC_40.vmdk | Possibly a Zombie vmdk file! Please check. | b4dd9b40-0cee-4a54-8244-5b5806ac210a |
[zombi-Migration_Data_LUN_13] SRM-StorageM/zombi-system.vmdk | Possibly a Zombie vmdk file! Please check. | b4dd9b40-0cee-4a54-8244-5b5806ac210a |
[zombi-Migration_Data_LUN_13] Linux9_CE/Linux10_CE.vmdk | Possibly a Zombie vmdk file! Please check. | b4dd9b40-0cee-4a54-8244-5b5806ac210a |
[zombi-Migration_Data_LUN_13] Linux5_CE/zombi-Linux5_CE.vmdk | Possibly a Zombie vmdk file! Please check. | b4dd9b40-0cee-4a54-8244-5b5806ac210a |
[zombi-Migration_Data_LUN_13] Linux8_CE/zombi-Linux9_CE_6.vmdk | Possibly a Zombie vmdk file! Please check. | b4dd9b40-0cee-4a54-8244-5b5806ac210a |
[zombi-Migration_Data_LUN_13] Linux8_CE/zombi-Linux9_CE_2.vmdk | Possibly a Zombie vmdk file! Please check. | b4dd9b40-0cee-4a54-8244-5b5806ac210a |
[zombi-Migration_Data_LUN_13] Linux8_CE/zombi-Linux9_CE_3.vmdk | Possibly a Zombie vmdk file! Please check. | b4dd9b40-0cee-4a54-8244-5b5806ac210a |
[zombi-Migration_Data_LUN_13] Linux8_CE/zombi-Linux9_AE_4.vmdk | Possibly a Zombie vmdk file! Please check. | b4dd9b40-0cee-4a54-8244-5b5806ac210a |
Thanks
vmk2014
Is this '3026?EBS-1-XIO_LUN_153' a name of one of your datastores?
And do you actually have a question mark in that datastorename?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
Data store name , i pulled from RVtools report is below
[3026–EBS-1-XIO_LUN_153] DCDDALLNX428_CE/zombie-DCDDALLNX428_CE_18.vmdk
Let me know if you need further info.
thanks
vmk2014
So I'm wondering how that question mark got in there ?!?
I'll do some test to see if I can recreate
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
[3026–EBS-1-XIO_LUN_153]
I may be wrong,. However, to me it looks like the first hyphen is no a regular one (ASCII '2D'), but a special character, likely ASCII '96'.
André
Thanks André, that could indeed be the cause (Import-CSV has issues with importing UTF-8 files that do not have a BOM.
A possible bypass could be doing it this way (Get-Content does this correctly).
$file = 'C:\RVTools_tabvHealth.csv'
$driveName = 'DS'
$report = @()
# Cleanup leftovers
Get-PSDrive -Name $driveName -ErrorAction SilentlyContinue | Remove-PSDrive -Confirm:$False -ErrorAction SilentlyContinue
Get-Content -Path $file | ConvertFrom-Csv | where{$_.Message -match 'Possibly a Zombie vmdk file'} |
Group-Object -Property {$_.Name.Split(']')[0].Trimstart('[')} | %{
$ds = Get-Datastore -Name $_.Name
Try{
New-PSDrive -Name $driveName -PSProvider VimDatastore -Root \ -Location $ds > $null
}
Catch{
Write-Host "Could not create PSDrive for $($ds.Name)"
break
}
$_.Group | %{
$vmdkPath = "$($driveName)😕$($_.Name.Split(' ')[1])"
if(Test-Path -Path $vmdkPath){
$report += (Get-ChildItem -Path $vmdkPath | Select DatastoreFullPath,LastWriteTime)
}
else{
Write-Host "VMDK $($vmdkPath) not found"
}
}
Remove-PSDrive -Name DS -ErrorAction SilentlyContinue
}
#$report | Export-Csv report.csv -NoTypeInformation -UseCulture
$report
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
Apology for replying late. I did ran the script once again but it throws same error
PowerCLI C:\temp> .\Time-Stamp.ps1
VMDK DS:\3029POC/3029POC_9.vmdk not found
VMDK DS:\3029POC/3029POC_1.vmdk not found
VMDK DS:\3029POC/3029POC_3.vmdk not found
VMDK DS:\3029POC/3029POC_5.vmdk not found
VMDK DS:\3029POC/3029POC_7.vmdk not found
VMDK DS:\3029POC/3029POC_16.vmdk not found
VMDK DS:\3029POC/3029POC_14.vmdk not found
VMDK DS:\3029POC/3029POC_21.vmdk not found
VMDK DS:\3029POC/3029POC_29.vmdk not found
VMDK DS:\3029POC/3029POC_37.vmdk not found
VMDK DS:\3029POC/3029POC_35.vmdk not found
VMDK DS:\3029POC/3029POC_33.vmdk not found
VMDK DS:\3029POC/3029POC_31.vmdk not found
VMDK DS:\3029POC/3029POC_39.vmdk not found
VMDK DS:\3029POC/3029POC_45.vmdk not found
VMDK DS:\3029POC/3029POC_43.vmdk not found
VMDK DS:\3029POC/3029POC_41.vmdk not found
Get-Datastore : 8/8/2016 2:21:08 PM Get-Datastore Datastore with
name 'XIO_LUN_126' was not found using the specified filter(s).
At C:\temp\Time-Stamp.ps1:10 char:11
+ $ds = Get-Datastore -Name $_.Name
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-Datastore], VimExceptio
n
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimA
utomation.ViCore.Cmdlets.Commands.GetDatastore
thanks
vmk 2014
Not exactly the same error, the question mark is gone.
I assume when you do a 'Get-Datastore -Name XIO_LUN_126' a datastore object is returned?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Sorry, its my bad.
Please find the input..
PowerCLI C:\temp> Get-Datastore -Name XIO_LUN_126
Get-Datastore : 8/8/2016 3:58:01 PM Get-Datastore Datastore with
name 'XIO_LUN_126' was not found using the specified filter(s).
At line:1 char:1
+ Get-Datastore -Name XIO_LUN_126
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-Datastore], VimExceptio
n
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimA
utomation.ViCore.Cmdlets.Commands.GetDatastore
thanks
vmk2014
Does this mean there was an obsolete datastore in the list?
Is the script working for all other entries?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference