Last active
August 5, 2020 00:55
-
-
Save technion/50c3ebe75f6ccfed0b94b5a916b5c002 to your computer and use it in GitHub Desktop.
Scan a virtualdisk for VMs that are using it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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