Identify VMDK sharing

Some times we may need to find out whether VMDK files are shared with some other vms. Using below script we an easily find that. We just need to give the vm name & it  will check for all the vmdk paths in all the VMS

 

connect-viserver vcentername

$vmname=read-host -Prompt “Enter the VM Name”

 

if (get-vm $vmname -erroraction SilentlyContinue)

{

$vdisk=get-vm $vmname |Get-VMHardDiskDrive

 

 

$allvms=get-vm

 

 

foreach ($allvm in $allvms)

{

if ($allvm.name -ne $vmname)

{

$vmdiskpath=get-vm $allvm |get-harddisk

foreach($disk in $vdisk)

{

if ($vmdiskpath.filename -eq $disk.filename)

{

$msg=”There is a VMDKS sharing with ”

$msg2=$allvm.name

$fullmsg=$msg+$msg2

Write-Host $fullmsg -ForegroundColor DarkGreen

}

}

}

 

}

}

else

{

Write-Host “VM is not available in the vCenter, please check the vm name”

}

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: