Automation

 View Only
Expand all | Collapse all

Need a PowerCLI script to delete Orphaned VMDK from datastore

  • 1.  Need a PowerCLI script to delete Orphaned VMDK from datastore

    Posted May 30, 2022 04:03 PM

    Hi,

    We have list of Orphaned VMDK's in datastores and I am looking for PowerCLI script to delete those VMDK's directly from datastore.

    The list is in excel format which contains vCenters name, Datastore Name and Disk(VMDK) path and last modification date/time.

    Looking for script with check condition whether VMDK is connected to any VM or not, if not connected then proceed with deletion. 

    NOTE: Datastores are VVOLS

    Thanks.

     



  • 2.  RE: Need a PowerCLI script to delete Orphaned VMDK from datastore

    Posted May 30, 2022 04:56 PM

    Did you try the script in Orphaned Files Revisited?



  • 3.  RE: Need a PowerCLI script to delete Orphaned VMDK from datastore

    Posted May 31, 2022 11:36 AM

    Hi LucD,

    Thanks for your reply.

    Can you help me with script to delete orphaned vmdk from the given datastore path. Before it delete, need to include a check whether VMDK is connected to any VM or not.

    Thanks.

     



  • 4.  RE: Need a PowerCLI script to delete Orphaned VMDK from datastore

    Posted May 31, 2022 11:52 AM

    That is exactly what that blog post is showing.
    Did you read the post and try the script?

    If you want a Delete switch, that is what my other post Orphaned files and folders – Spring cleaning is providing.



  • 5.  RE: Need a PowerCLI script to delete Orphaned VMDK from datastore

    Posted Jun 06, 2022 03:18 PM

    Hi 

    I have path like below, can you tell me how to get this into script to identify the datastore. 

    ds:///vmfs/vvol/d48954a25695-8hfyrd475jfurjfv/fcr4111.ca4564c7-7c70-470e-aeec/vmname.vmdk

     

    Thanks.



  • 6.  RE: Need a PowerCLI script to delete Orphaned VMDK from datastore

    Posted Jun 06, 2022 04:53 PM

    How did you obtain this path?
    And how is this related to your original question about orphaned VMDKs?



  • 7.  RE: Need a PowerCLI script to delete Orphaned VMDK from datastore

    Posted Jun 06, 2022 05:04 PM

    Hi LucD,

     

    Actually datastores are vvols and all orphaned VMDK's are residing on these paths. I understand this is kind of root path, but these data pulled out by using a tool and it gives data in this way, Can we have any way to  include in script to identify the datastore by using this root path?

     

    Thanks



  • 8.  RE: Need a PowerCLI script to delete Orphaned VMDK from datastore
    Best Answer

    Posted Jun 06, 2022 05:52 PM

    I don't have any VVOLs to test, but with the following you should be able to map datastore names to part of those paths you have.

    Get-Datastore -PipelineVariable ds | where{$_.Type -eq 'VVOL'}  |
    ForEach-Object -Process {
        $_.ExtensionData.Info |
        Select @{N='DS';E={$ds.Name}},*
    }


  • 9.  RE: Need a PowerCLI script to delete Orphaned VMDK from datastore

    Posted Jun 13, 2022 01:45 PM

    Hi LucD,

    Tried a lot but I couldn't make this, Can you please help me with the script. My requirement is just want to delete the VMDK from below datastore path provided through .CSV file. Before it deletes need to check whether its connected to any VM or not.

    ds:///vmfs/vvol/d48954a25695-8hfyrd475jfurjfv/fcr4111.ca4564c7-7c70-470e-aeec/vmname.vmdk

     

    Thanks. 



  • 10.  RE: Need a PowerCLI script to delete Orphaned VMDK from datastore

    Posted Jun 13, 2022 06:53 PM

    Since I don't use/have VVOLs I can't test, so I rely on what you see, but "... but I couldn't make this" doesn't really help I'm afraid.



  • 11.  RE: Need a PowerCLI script to delete Orphaned VMDK from datastore

    Posted Jun 14, 2022 09:44 AM

    Hi LucD,

    It helps, I can get the root path datastore but, I don't know how to browse the VMDK exactly to path in powercli script. It would be very much helpful if you help me with the script. Apart from vvols, I have other VMFS datastores as well. 

    Thanks.



  • 12.  RE: Need a PowerCLI script to delete Orphaned VMDK from datastore

    Posted Apr 04, 2023 06:29 PM

    Hi there, 

    I have exactly the same situation . were you able find a PowerCLI cmd (or script) to delete orphaned VMDK with the path like ds:///vmfs/vvol/d48954a25695-8hfyrd475jfurjfv/fcr4111.ca4564c7-7c70-470e-aeec/vmname.vmd ? 

     

    Thanks,