Skip to content

Instantly share code, notes, and snippets.

@technion
Last active August 5, 2020 00:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save technion/50c3ebe75f6ccfed0b94b5a916b5c002 to your computer and use it in GitHub Desktop.
Save technion/50c3ebe75f6ccfed0b94b5a916b5c002 to your computer and use it in GitHub Desktop.
Scan a virtualdisk for VMs that are using it
# Please set these two variables
$scanpath = "C:\ClusterStorage\SilverTier1"
$clustername = "cls.cluster.mycluster.cluster.cls"
Set-StrictMode -Version 2
$nodes = Get-ClusterNode -Cluster $clustername
foreach ($node in $nodes) {
write-host "Processing node $($node.Name)"
$vms = Get-VM -ComputerName $node
foreach ($vm in $vms) {
if ($vm.Path -like "$scanpath*") {
Write-Host "VM $($vm.Name) has base path at $($vm.Path)"
# No need to continue, we know this VM is worth looking at
continue
}
foreach($disk in ($vm | Get-VMHardDiskDrive)) {
if ($disk.Path -like "$scanpath*") {
write-host "VM $($vm.Name) has disk at path $($disk.Path)"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment