<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Delete snapshot and monitor progress and display success if 100% successful or error for each VM in VMware PowerCLI Discussions</title>
    <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Delete-snapshot-and-monitor-progress-and-display-success-if-100/m-p/2932248#M108635</link>
    <description>&lt;P&gt;Excellent as always. Thank you.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 06 Oct 2022 14:31:24 GMT</pubDate>
    <dc:creator>BBB36</dc:creator>
    <dc:date>2022-10-06T14:31:24Z</dc:date>
    <item>
      <title>Delete snapshot and monitor progress and display success if 100% successful or error for each VM.</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Delete-snapshot-and-monitor-progress-and-display-success-if-100/m-p/2932179#M108617</link>
      <description>&lt;P&gt;I have this script with the intention of monitoring the snapshot deletion progress and stating if it was successful or not for each VM.&lt;BR /&gt;Right now when I run it, it doesn't do anything. Can someone please help modify it so that it can output the progress and success of a snapshot deletion for each VM? Thanks.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;$vCenterCredential = Get-Credential -Message "Enter account with access to the vCenter(s)" -ErrorAction SilentlyContinue;
$vCenters = Get-Content -Path "D:\Scripts\vclist.txt"
Connect-VIServer -Server $vCenters -Credential $vCenterCredential -Protocol https | Out-Null
$vmlist = Get-Content "D:\Scripts\vmlist.txt"
foreach($vm in $vmlist) {
Get-VM -Name $vm | Get-Snapshot |
   ForEach-Object -Process {
   Remove-Snapshot -Snapshot $_ -Confirm:$false -RunAsync
   $current = Get-Task | where {$_.Name -eq 'RemoveSnapshot_Task' -and 'Running','Queued' -contains $_.State}
   $runningTasks = $taskTab.Count
	while ($runningTasks -gt 0) {
	Get-Task | % {
      if ($taskTab.ContainsKey($_.Id) -and $_.State -eq "Success") {
         $vm = Get-VM $taskTab[$_.Id]
         Write-Host $vm snapshot is being deleted. -foregroundcolor red
		$taskTab.Remove($_.Id)
         $runningTasks--
       }
        elseif ($taskTab.ContainsKey($_.Id) -and $_.State -eq "Error") {
        $taskTab.Remove($_.Id)
        $runningTasks--
       }
      }
    }
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Oct 2022 05:24:12 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Delete-snapshot-and-monitor-progress-and-display-success-if-100/m-p/2932179#M108617</guid>
      <dc:creator>BBB36</dc:creator>
      <dc:date>2022-10-06T05:24:12Z</dc:date>
    </item>
    <item>
      <title>Re: Delete snapshot and monitor progress and display success if 100% successful or error for each VM</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Delete-snapshot-and-monitor-progress-and-display-success-if-100/m-p/2932195#M108619</link>
      <description>&lt;P&gt;You didn't specify that $taskTab is a hash table, and there are a couple of other things missing.&lt;BR /&gt;Try something like this&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;$vCenterCredential = Get-Credential -Message "Enter account with access to the vCenter(s)" -ErrorAction SilentlyContinue;
$vCenters = Get-Content -Path "D:\Scripts\vclist.txt"
Connect-VIServer -Server $vCenters -Credential $vCenterCredential -Protocol https | Out-Null

$taskTab = @{}

$vmlist = Get-Content "D:\Scripts\vmlist.txt"

Get-VM -Name $vmlist -PipelineVariable vm |
Get-Snapshot -PipelineVariable snap |
ForEach-Object -Process {
  $task = Remove-Snapshot -Snapshot $_ -Confirm:$false -RunAsync
  $taskTab.Add($task.Id, "VM: $($vm.Name) - Snapshot: $($snap.Name)")
}

$runningTasks = $taskTab.Count
while ($runningTasks -gt 0) {
  Get-Task | ForEach-Object {
    if ($taskTab.ContainsKey($_.Id) -and $_.State -eq "Success") {
      Write-Host "$($taskTab[$_.Id]) was deleted." -ForegroundColor red
      $taskTab.Remove($_.Id)
      $runningTasks--
    } elseif ($taskTab.ContainsKey($_.Id) -and $_.State -eq "Error") {
      $taskTab.Remove($_.Id)
      $runningTasks--
    }
  }
}
&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 06 Oct 2022 07:36:16 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Delete-snapshot-and-monitor-progress-and-display-success-if-100/m-p/2932195#M108619</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2022-10-06T07:36:16Z</dc:date>
    </item>
    <item>
      <title>Re: Delete snapshot and monitor progress and display success if 100% successful or error for each VM</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Delete-snapshot-and-monitor-progress-and-display-success-if-100/m-p/2932248#M108635</link>
      <description>&lt;P&gt;Excellent as always. Thank you.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Oct 2022 14:31:24 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Delete-snapshot-and-monitor-progress-and-display-success-if-100/m-p/2932248#M108635</guid>
      <dc:creator>BBB36</dc:creator>
      <dc:date>2022-10-06T14:31:24Z</dc:date>
    </item>
  </channel>
</rss>

