I'm hoping someone can tell me why my script won't complete. I'm trying to display and delete snapshots that are leftover by Commvault. I have it written so I can search by Name or Description by removing the marking or un-marking your preference. Everything works except for the section in "blue" below. My variable, $snaps, shows the desired output but the code below it won't delete the snapshots. It doesn't have any errors or give me a reason why it's not working.
* Parts of the script below came from other sources.
Hoping someone can assist me.
Thanks,
Charles
*********************************************************************************
## Loads VMWare PowerCLI ##
$ErrorActionPreference = "SilentlyContinue";
$ProgressPreference = "SilentlyContinue";
Add-PSSnapin VMWare* -ea SilentlyContinue
Import-Module VMWare* -ea SilentlyContinue
# Connects to the desired vCenter
Connect-VIServer fetsvmvc01.ftbco.ftn.com
# Sets the maximum number of taks that can run in vCenter (don't want to overload the storage with too many IOPs)
$maxtasks = 4
#Clear Screen!
CLS
# Lists all snapshots based on the Name or Description and deletes them.
$snaps = get-vm | get-snapshot | where {$_.Name -match "__GX_BACKUP__"}| Format-Table -Property VM,Name,Created,Description, SizeMB
# $snaps = get-vm | get-snapshot | where {$_.Description -match "Snapshot created by Commvault"}| Format-Table -Property VM,Name,Created,Description, SizeMB
#Show the contents of the variable
$snaps
$i = 0
while($i -lt $snaps.Count){
Remove-Snapshot -Snapshot $snaps[$i] -RunAsync -Confirm:$false
$tasks = Get-Task -Status “Running” | where {$_.Name -eq “RemoveSnapshot_Task”}
while($tasks.Count -gt ($maxtasks-1)) {
sleep 30
$tasks = Get-Task -Status “Running” | where {$_.Name -eq “RemoveSnapshot_Task”}
}
$i++
}