PowerCLI

 View Only
Expand all | Collapse all

Finding the last modified date for Orphaned vmdk file

  • 1.  Finding the last modified date for Orphaned vmdk file

    Posted Aug 03, 2016 05:27 PM

    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



  • 2.  RE: Finding the last modified date for Orphaned vmdk file

    Posted Aug 03, 2016 05:51 PM

    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.



  • 3.  RE: Finding the last modified date for Orphaned vmdk file

    Posted Aug 03, 2016 06:15 PM

    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



  • 4.  RE: Finding the last modified date for Orphaned vmdk file

    Posted Aug 04, 2016 05:55 AM

    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



  • 5.  RE: Finding the last modified date for Orphaned vmdk file

    Posted Aug 04, 2016 08:37 PM

    Thanks LucD. its working but when i added the line $report | Export-Csv "C:\Temp\TimeStamp.csv" -NoTypeInformation -UseCulture

    throw an error.

    PFA screenshot attached.

    thanks

    vmk2014



  • 6.  RE: Finding the last modified date for Orphaned vmdk file

    Posted Aug 04, 2016 09:11 PM

    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



  • 7.  RE: Finding the last modified date for Orphaned vmdk file

    Posted Aug 05, 2016 04:14 AM

    Thanks LucD. Unfortunately this time doesn't generate any output. It throws error ( attached in mail thread).

    thanks

    vmk2014



  • 8.  RE: Finding the last modified date for Orphaned vmdk file

    Posted Aug 05, 2016 04:57 AM

    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



  • 9.  RE: Finding the last modified date for Orphaned vmdk file

    Posted Aug 05, 2016 06:48 AM

    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



  • 10.  RE: Finding the last modified date for Orphaned vmdk file

    Posted Aug 05, 2016 02:35 PM

    Hi LucD,

    No this again different error :smileysad:.  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



  • 11.  RE: Finding the last modified date for Orphaned vmdk file

    Posted Aug 05, 2016 02:41 PM

    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



  • 12.  RE: Finding the last modified date for Orphaned vmdk file

    Posted Aug 05, 2016 03:32 PM

    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?



  • 13.  RE: Finding the last modified date for Orphaned vmdk file

    Posted Aug 05, 2016 05:58 PM

    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



  • 14.  RE: Finding the last modified date for Orphaned vmdk file

    Posted Aug 05, 2016 07:09 PM

    So I'm wondering how that question mark got in there ?!?
    I'll do some test to see if I can recreate



  • 15.  RE: Finding the last modified date for Orphaned vmdk file

    Posted Aug 05, 2016 07:23 PM

    [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é



  • 16.  RE: Finding the last modified date for Orphaned vmdk file
    Best Answer

    Posted Aug 06, 2016 08:33 AM

    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



  • 17.  RE: Finding the last modified date for Orphaned vmdk file

    Posted Aug 08, 2016 07:17 PM

    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



  • 18.  RE: Finding the last modified date for Orphaned vmdk file

    Posted Aug 08, 2016 08:47 PM

    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?



  • 19.  RE: Finding the last modified date for Orphaned vmdk file

    Posted Aug 08, 2016 08:59 PM

    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



  • 20.  RE: Finding the last modified date for Orphaned vmdk file

    Posted Aug 09, 2016 05:22 AM

    Does this mean there was an obsolete datastore in the list?

    Is the script working for all other entries?



  • 21.  RE: Finding the last modified date for Orphaned vmdk file

    Posted Aug 09, 2016 02:20 PM

    Yes, its for all entries same output.  Lucd, when first time you replied that option worked well, only difference that i was looking for CSV export which never worked until now.

    $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

    }


    thanks

    vmk2014



  • 22.  RE: Finding the last modified date for Orphaned vmdk file

    Posted Aug 09, 2016 03:20 PM

    So all entries give that same type of error, is that what you are saying?

    I don't get that, the part the extracts the datastorename and gets the datastore hasn't changed between those two versions of the script.



  • 23.  RE: Finding the last modified date for Orphaned vmdk file

    Posted Aug 09, 2016 03:29 PM

    Yes, LucD, i meant to say same type of error.

    VMDK DS:\3029POC/3029POC_2.vmdk not found

    VMDK DS:\3029POC/3029POC_4.vmdk not found

    VMDK DS:\3029POC/3029POC_6.vmdk not found

    VMDK DS:\3029POC/3029POC_17.vmdk not found

    VMDK DS:\3029POC/3029POC_15.vmdk not found

    VMDK DS:\3029POC/3029POC_13.vmdk not found

    VMDK DS:\3029POC/3029POC_11.vmdk not found

    VMDK DS:\3029POC/3029POC_19.vmdk not found

    VMDK DS:\3029POC/3029POC_27.vmdk not found

    VMDK DS:\3029POC/3029POC_25.vmdk not found

    VMDK DS:\3029POC/3029POC_23.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

    vmk2014



  • 24.  RE: Finding the last modified date for Orphaned vmdk file

    Posted Aug 09, 2016 05:27 PM

    I'm completely confused now.

    From the output you showed, it looks as if the datastore on which the folder 3029POC is located, does seem to work correctly.

    Otherwise you wouldn't see the message "....vmdk not found".

    From what I see, the "Datastore not found" message only appears for a number of datastores.

    At first we thought it was due to the special characters in the datastorename.

    By doing a Get-Content instead of an Import-Csv that problem seems to have been fixed, no more question mark in the datastorename.

    But then you still get the "datastore not found" message.

    That is why I asked to try a Get-Datastore with that datastorename, from that it looked as if the datastore was not present in the environment to which you were connected.

    I'm not sure where the actual problem is right now.



  • 25.  RE: Finding the last modified date for Orphaned vmdk file

    Posted Jan 12, 2022 07:44 PM

    I found that your script had a "confused_face" emoji in it. $vmdkPath = "$($driveName)$($_.Name.Split(' ')[1])"

    Which when copied and pasted into power shell it showed up in the script as this: $vmdkPath = "$($driveName):confused_face:$($_.Name.Split(' ')[1])"

    That is why you get vmdk not found. Just delete the ":confused_face" line of the code and it will work.

    I also made sure to copy the Health tab out of RVTools to it's own file and saved as .csv

    I hope that helps. -Stephen J

    $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 C:\temp\Zombiereport.csv -NoTypeInformation -UseCulture

    $report