VMware Cloud Community
Vel_VMware
Enthusiast
Enthusiast
Jump to solution

Need a PowerCLI script to delete Orphaned VMDK from datastore

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.

 

Labels (1)
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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}},*
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

11 Replies
LucD
Leadership
Leadership
Jump to solution

Did you try the script in Orphaned Files Revisited?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Vel_VMware
Enthusiast
Enthusiast
Jump to solution

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.

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Vel_VMware
Enthusiast
Enthusiast
Jump to solution

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.

Tags (1)
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Vel_VMware
Enthusiast
Enthusiast
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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}},*
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Vel_VMware
Enthusiast
Enthusiast
Jump to solution

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. 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Vel_VMware
Enthusiast
Enthusiast
Jump to solution

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.

Reply
0 Kudos
idigit
Contributor
Contributor
Jump to solution

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,

Reply
0 Kudos