Thanks, i did look at something like that earlier but it didn't do what i wanted. I wrote this.
This script is specifically designed to go through a Cluster, check for 2 datastores with matching "name1" and "name2", creates a snapshot and then deletes it. Its purposed was for svmotion linked-clone issue where a svmotion attempt would be successful but still leave trace of the old datastore. This messed up our reports and was the reason for this script.
Probably a one time deal, but its nice event though it could use polish.
Connect-VIServer -Server $server
$dsnum = 2
$vservers = get-cluster "cluster1" |Get-VM ; foreach ($vserver in $vservers){
$var2 = (get-vm $vserver | get-datastore | Measure-Object).Count
$var = get-vm $vserver | get-datastore
foreach ($_ in $var)
{
if (($_.Name -match "xxx1") -and ($_.Name -match "xxx2") -and ($var2 -ge $dsnum ))
{
Write-host "Listed DataStores $var" -BackgroundColor DarkMagenta -ForegroundColor White
Write-Host "Match $vserver" -fore Blue
Get-VM $vserver | New-Snapshot -Name "Snap01"
Get-VM $vserver | get-snapshot | Remove-Snapshot -confirm:$false
$var3 = get-vm $vserver | get-datastore
write-host "Updated $vserver Listed DataStores $var3" -ForegroundColor Cyan
}
elseif ($var2 -lt $dsnum ){
write-host "Server Not Matched $vserver" -BackgroundColor Black -ForegroundColor White
}
}
}
Disconnect-VIServer -confirm:$false