VMware Cloud Community
Christopher_
Contributor
Contributor
Jump to solution

Moving and Deleting VMDKs via PowerCLI in vSphere 6.5

Previously helped here:

Move, Remove, or Copy an orphaned VMDK all result in a Flat file?

From that thread for 5.5 I have a script that is basically:

$si = Get-View ServiceInstance

$vmdkMgr = Get-View $si.content.VirtualDiskManager

$ds = (a datastore object)

$file = '[Datastore] Path/File.vmdk'

$dcObj = Get-VMhost -Datastore $ds | Get-Datacenter

$vmdkMgr.DeleteVirtualDisk($file,$DCobj)

Summarized as it's part of a loop processing a report but more or less the above and it's working.

Problem is 6.5 managed files return 'A general system error occurred: The part of this virtual disk could not be opened'

Looking into it for 6.5 I need to instead use the VStorageObjectManager and the DeleteVStorageObject task using IDs from ListVStorageObject.

I've attempted:

$si = Get-View ServiceInstance

$vStorageMgr = Get-View $si.content.VStorageObjectManager

$ds = (a datastore object)

$dsView = Get-View $ds

$vStorageMgr.ListVStorageObject($dsView.MoRef)

Which yields no results or errors.

Am I missing something? To move/delete the VMDKs I need IDs provided from ListVStorageObject right?

Or is there a way to get this ID required by the VStorageObjectManager if I know the specific file I want to interact with?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Btw, did you actually create those VMDK as vStorageObjects?

If not, then you don't need the DeleteVirtualDisk method.

If the VMDK is not located on a VSAN datastore, then the DeleteVirtaulDisk method should be just fine.

Do you get that error for all VMDK you try to remove?


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

View solution in original post

0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

Are these files you want to remove on VSAN datastores?


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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Btw, did you actually create those VMDK as vStorageObjects?

If not, then you don't need the DeleteVirtualDisk method.

If the VMDK is not located on a VSAN datastore, then the DeleteVirtaulDisk method should be just fine.

Do you get that error for all VMDK you try to remove?


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

0 Kudos
Christopher_
Contributor
Contributor
Jump to solution

Tried running it again after your response and it worked this time.

Not really sure what happened last couple of runs but seemed the errors were isolated to only VMDKs on 6.5 so figured that was the issue.

Guess it ran while we were patching or something else unrelated borked the script.

0 Kudos