Do to some "creative" design decisions early on in our implementation, we have a lot of datastores. As we fix those creative decisions, we are accumulating quite a few of datastores that are no longer in use. I wrote a little script to help me identify datastores without VMs.
#Outputs a list of unused datastores
ForEach ($ds in get-datastore) {
# I like output in objects
$Output = New-Object -TypeName System.Management.Automation.PSObject
Add-Member -InputObject $Output NoteProperty DataStoreName $ds.Name
#This will tell us if any VMs see the datastore.
$VMs = get-vm -Datastore $ds
If ($VMs){
Add-Member -InputObject $Output NoteProperty HasVMs "Yes"
}Else{
Add-Member -InputObject $Output NoteProperty HasVMs "No"
}
$Output
}