<?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: Snapshot Deletion in VMware PowerCLI Discussions</title>
    <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Snapshot-Deletion/m-p/2993943#M113675</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS C:\Users\pjhowarth&amp;gt; Date&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thursday, November 2, 2023 11:07:37 AM&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS C:\Users\&amp;gt; $ca = Get-CustomAttribute -Name 'snapshot_date'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS C:\Users\&amp;gt; $ca&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Key&amp;nbsp;&amp;nbsp; Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TargetType&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;---&amp;nbsp;&amp;nbsp; ----&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ----------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;108&amp;nbsp;&amp;nbsp; snapshot_date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS C:\Users\&amp;gt; Get-Annotation -Entity $_.vm -CustomAttribute $ca&lt;/P&gt;&lt;P&gt;Get-Annotation : Cannot validate argument on parameter 'Entity'. The argument is null. Provide a valid value for the argument, and then&lt;/P&gt;&lt;P&gt;try running the command again.&lt;/P&gt;&lt;P&gt;At line:1 char:24&lt;/P&gt;&lt;P&gt;+ Get-Annotation -Entity $_.vm -CustomAttribute $ca&lt;/P&gt;&lt;P&gt;+&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ~~~~~&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; + CategoryInfo&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : InvalidData: (:) [Get-Annotation], ParameterBindingValidationException&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetAnnotation&lt;/P&gt;</description>
    <pubDate>Thu, 02 Nov 2023 15:19:11 GMT</pubDate>
    <dc:creator>Pete_Howarth3</dc:creator>
    <dc:date>2023-11-02T15:19:11Z</dc:date>
    <item>
      <title>Snapshot Deletion</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Snapshot-Deletion/m-p/2993894#M113667</link>
      <description>&lt;P&gt;I found the script below to delete snaps older than 5 days.&amp;nbsp; Is there a way to have it look at a date value assigne to a custom attibute called say snapshot_date and ignore deleting that snapshot until that date arrives?&amp;nbsp; For devs that want to keep a snapshot for until a specific date in the future?&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;$&lt;/SPAN&gt;&lt;SPAN&gt;vcenter&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;hostname&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;$&lt;/SPAN&gt;&lt;SPAN&gt;creds&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Get-VICredentialStoreItem&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;-&lt;/SPAN&gt;file&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;C:\Vmware script\pass.cred&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;#Connect to the vCenter server defined above. Ignore certificate errors&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;connect-viserver&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;$&lt;/SPAN&gt;&lt;SPAN&gt;vcenter&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;-&lt;/SPAN&gt;User&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;$&lt;/SPAN&gt;&lt;SPAN&gt;creds.User&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;-&lt;/SPAN&gt;Password&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;$&lt;/SPAN&gt;&lt;SPAN&gt;creds.Password&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;-&lt;/SPAN&gt;WarningAction&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;$&lt;/SPAN&gt;&lt;SPAN&gt;excludeNamesRegEx&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;donotdelete|donttouch|stayaway&lt;/SPAN&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Clear-Host&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Get-VM&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;|&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Get-Snapshot&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;|&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Where&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;{$&lt;/SPAN&gt;&lt;SPAN&gt;_.Created&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;-lt&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;Get-Date&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;.AddDays&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;-5&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;-and&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;$&lt;/SPAN&gt;&lt;SPAN&gt;_.Name&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;-notmatch&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;$&lt;/SPAN&gt;&lt;SPAN&gt;excludeNamesRegEx&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;|&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Remove-Snapshot&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;-&lt;/SPAN&gt;Confirm:&lt;SPAN&gt;$&lt;/SPAN&gt;&lt;SPAN&gt;false&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2023 11:51:31 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Snapshot-Deletion/m-p/2993894#M113667</guid>
      <dc:creator>Pete_Howarth3</dc:creator>
      <dc:date>2023-11-02T11:51:31Z</dc:date>
    </item>
    <item>
      <title>Re: Snapshot Deletion</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Snapshot-Deletion/m-p/2993902#M113668</link>
      <description>&lt;P&gt;Try something like this&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;$ca = Get-CustomAttribute -Name 'snapshot_date'
$now = Get-Date

Get-VM | Get-Snapshot |
where{(Get-Annotation -Entity $_.vm -CustomAttribute $ca).Value -ge $now} |
Remove-Snapshot -Confirm:$false&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 02 Nov 2023 12:13:13 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Snapshot-Deletion/m-p/2993902#M113668</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2023-11-02T12:13:13Z</dc:date>
    </item>
    <item>
      <title>Re: Snapshot Deletion</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Snapshot-Deletion/m-p/2993909#M113670</link>
      <description>&lt;P&gt;Is there a way to combine the two scripts so that I can have a jumpbox run it daily.&amp;nbsp; Delete any snaps that are 3 days old or 5 days old that it finds.&amp;nbsp; Ignore vm's with snaps that have that future date value until that date arrives?&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2023 12:51:34 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Snapshot-Deletion/m-p/2993909#M113670</guid>
      <dc:creator>Pete_Howarth3</dc:creator>
      <dc:date>2023-11-02T12:51:34Z</dc:date>
    </item>
    <item>
      <title>Re: Snapshot Deletion</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Snapshot-Deletion/m-p/2993912#M113671</link>
      <description>&lt;P&gt;You could combine those in that Where-clause&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;where{$_.Created -lt (Get-Date).AddDays(-5) -and (Get-Annotation -Entity $_.vm -CustomAttribute $ca).Value -le $now} |
&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 02 Nov 2023 13:04:26 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Snapshot-Deletion/m-p/2993912#M113671</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2023-11-02T13:04:26Z</dc:date>
    </item>
    <item>
      <title>Re: Snapshot Deletion</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Snapshot-Deletion/m-p/2993929#M113672</link>
      <description>&lt;P&gt;I noticed that it's not storing the date value in $ca for the custom attribute named snapshot_date.&lt;/P&gt;&lt;P&gt;$ca = Get-CustomAttribute -Name 'snapshot_date'&lt;BR /&gt;$now = Get-Date&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I set the value of $ca to 11/3/2023 a future date and change the .addDays(0) it will delete the snapshot even though $ca has a future date value.&lt;/P&gt;&lt;P&gt;where{$_.Created -lt (Get-Date).AddDays(-0) -and (Get-Annotation -Entity $_.vm -CustomAttribute $ca).Value -le $now} |&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2023 14:38:58 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Snapshot-Deletion/m-p/2993929#M113672</guid>
      <dc:creator>Pete_Howarth3</dc:creator>
      <dc:date>2023-11-02T14:38:58Z</dc:date>
    </item>
    <item>
      <title>Re: Snapshot Deletion</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Snapshot-Deletion/m-p/2993937#M113673</link>
      <description>&lt;P&gt;Are you sure it interprets '&lt;SPAN&gt;11/3/2023&lt;/SPAN&gt;' correctly?&lt;BR /&gt;What does this show as date?&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;[DateTime]'11/3/2023'&lt;/LI-CODE&gt;
&lt;P&gt;Also, the Where-clause compares the value in the CA to the content of the &lt;STRONG&gt;$now&lt;/STRONG&gt; variable.&lt;BR /&gt;&lt;BR /&gt;The first part of the condition (&lt;SPAN&gt;$_.Created -lt (Get-Date).AddDays(-5)&lt;/SPAN&gt;) checks if the snapshot was created more than 5 days ago.&lt;BR /&gt;The complete condition checks:&lt;BR /&gt;- if the snapshot was created more than 5 days ago&lt;BR /&gt;AND&lt;BR /&gt;- if the value in the CA is a date before now&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2023 14:54:00 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Snapshot-Deletion/m-p/2993937#M113673</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2023-11-02T14:54:00Z</dc:date>
    </item>
    <item>
      <title>Re: Snapshot Deletion</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Snapshot-Deletion/m-p/2993938#M113674</link>
      <description>&lt;P&gt;If the date format is in&amp;nbsp;MM/dd/yyyy h:mm:ss AM/PM, the sort result is not correct.&lt;/P&gt;&lt;P&gt;I have been working on report storage events from multiple arrays, the event creation time is&amp;nbsp;MM/dd/yyyy h:mm:ss AM/PM, I need to &amp;nbsp;convert the datetime to&amp;nbsp;DateTime objects, then do the sort, after the sort, convert the output back again for us to understand.&lt;/P&gt;&lt;P&gt;The code to sort date and time I used is as follows, hopefully this can help.&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;# Convert the data in the specified column to DateTime objects
    $dateColumn = $dataRange.Columns.Item("F")
    foreach ($cell in $dateColumn.Cells) {
    $cell.Value2 = [DateTime]::Parse($cell.Text)
   }

    # Perform the sort on the data range (descending order)
    $dataRange.Sort($dateColumn, 2) # Use 2 for descending order

    # Convert the sorted date and time values back to their original format
    foreach ($cell in $dateColumn.Cells) {
    $cell.NumberFormat = "MM/dd/yyyy h:mm:ss AM/PM"
}
    # Autofit all columns in the worksheet
    $usedRange.Columns.AutoFit()    &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2023 14:57:52 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Snapshot-Deletion/m-p/2993938#M113674</guid>
      <dc:creator>wetnose88</dc:creator>
      <dc:date>2023-11-02T14:57:52Z</dc:date>
    </item>
    <item>
      <title>Re: Snapshot Deletion</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Snapshot-Deletion/m-p/2993943#M113675</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS C:\Users\pjhowarth&amp;gt; Date&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thursday, November 2, 2023 11:07:37 AM&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS C:\Users\&amp;gt; $ca = Get-CustomAttribute -Name 'snapshot_date'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS C:\Users\&amp;gt; $ca&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Key&amp;nbsp;&amp;nbsp; Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TargetType&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;---&amp;nbsp;&amp;nbsp; ----&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ----------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;108&amp;nbsp;&amp;nbsp; snapshot_date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS C:\Users\&amp;gt; Get-Annotation -Entity $_.vm -CustomAttribute $ca&lt;/P&gt;&lt;P&gt;Get-Annotation : Cannot validate argument on parameter 'Entity'. The argument is null. Provide a valid value for the argument, and then&lt;/P&gt;&lt;P&gt;try running the command again.&lt;/P&gt;&lt;P&gt;At line:1 char:24&lt;/P&gt;&lt;P&gt;+ Get-Annotation -Entity $_.vm -CustomAttribute $ca&lt;/P&gt;&lt;P&gt;+&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ~~~~~&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; + CategoryInfo&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : InvalidData: (:) [Get-Annotation], ParameterBindingValidationException&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetAnnotation&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2023 15:19:11 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Snapshot-Deletion/m-p/2993943#M113675</guid>
      <dc:creator>Pete_Howarth3</dc:creator>
      <dc:date>2023-11-02T15:19:11Z</dc:date>
    </item>
    <item>
      <title>Re: Snapshot Deletion</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Snapshot-Deletion/m-p/2993945#M113676</link>
      <description>&lt;P&gt;You can't run that code line by line from the PS prompt.&lt;BR /&gt;The $_ variable is the object in the pipeline, i.e. the Snapshot object returned by Get-Snapshot.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2023 15:26:19 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Snapshot-Deletion/m-p/2993945#M113676</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2023-11-02T15:26:19Z</dc:date>
    </item>
    <item>
      <title>Re: Snapshot Deletion</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Snapshot-Deletion/m-p/2993948#M113677</link>
      <description>&lt;P&gt;I setup two vm's with snaps.&amp;nbsp; One with a custom attribute and a future date.&amp;nbsp; Run the code below and it deletes the snap on the vm with no custom attribute and leaves the other alone.&amp;nbsp; If I change the date on the other and run the code again.&amp;nbsp; It doesn't do anything.&amp;nbsp; I've tried using a Global and Virtual Machine Custom attribute using the values 11-02-2023 and 11/02/2023 to see if it would delete it with today's date.&amp;nbsp; It doesn't do anything.&amp;nbsp; No errors either.&lt;/P&gt;&lt;P&gt;$ca = Get-CustomAttribute -Name 'snapshot_date'&lt;BR /&gt;$now = Get-Date&lt;/P&gt;&lt;P&gt;Get-VM | Get-Snapshot |&lt;BR /&gt;where{$_.Created -lt (Get-Date).AddDays(-0) -and (Get-Annotation -Entity $_.vm -CustomAttribute $ca).Value -le $now} |&lt;BR /&gt;Remove-Snapshot -Confirm:$false&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2023 15:37:57 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Snapshot-Deletion/m-p/2993948#M113677</guid>
      <dc:creator>Pete_Howarth3</dc:creator>
      <dc:date>2023-11-02T15:37:57Z</dc:date>
    </item>
    <item>
      <title>Re: Snapshot Deletion</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Snapshot-Deletion/m-p/2993949#M113678</link>
      <description>&lt;P&gt;Did you check what is exactly in the CA?&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;Get-Annotation -Entity &amp;lt;VMname&amp;gt; -CustomAttribute $ca |
Select -ExpandProperty Value&lt;/LI-CODE&gt;
&lt;P&gt;Take note that the $now variable contains DateTime, i.e. today's date and the time.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2023 15:42:50 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Snapshot-Deletion/m-p/2993949#M113678</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2023-11-02T15:42:50Z</dc:date>
    </item>
    <item>
      <title>Re: Snapshot Deletion</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Snapshot-Deletion/m-p/2993950#M113679</link>
      <description>&lt;P&gt;The property value is 11-02-2023.&amp;nbsp; And the Get-Date is Thursday, November 2, 2023 11:45:35 AM.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2023 15:46:45 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Snapshot-Deletion/m-p/2993950#M113679</guid>
      <dc:creator>Pete_Howarth3</dc:creator>
      <dc:date>2023-11-02T15:46:45Z</dc:date>
    </item>
    <item>
      <title>Re: Snapshot Deletion</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Snapshot-Deletion/m-p/2993952#M113680</link>
      <description>&lt;P&gt;Okay got it to work by Setting the format value for $now = Get-Date- Format MM/dd/yyyy&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2023 15:53:05 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Snapshot-Deletion/m-p/2993952#M113680</guid>
      <dc:creator>Pete_Howarth3</dc:creator>
      <dc:date>2023-11-02T15:53:05Z</dc:date>
    </item>
    <item>
      <title>Re: Snapshot Deletion</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Snapshot-Deletion/m-p/2993954#M113681</link>
      <description>&lt;P&gt;Full script&lt;/P&gt;&lt;P&gt;$vcenter = "name of vcenter"&lt;/P&gt;&lt;P&gt;$creds = Get-VICredentialStoreItem -file "C:\Temp\pass.cred"&lt;/P&gt;&lt;P&gt;$ca = Get-CustomAttribute -Name 'snapshot_date'&lt;/P&gt;&lt;P&gt;$now = Get-Date -Format MM/dd/yyyy&lt;/P&gt;&lt;P&gt;#Connect to the vCenter server defined above. Ignore certificate errors&lt;/P&gt;&lt;P&gt;#connect-viserver $vcenter -User $creds.User -Password $creds.Password -WarningAction 0&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Clear-Host&lt;/P&gt;&lt;P&gt;Get-VM | Get-Snapshot |&lt;/P&gt;&lt;P&gt;where{$_.Created -lt (Get-Date).AddDays(-3) -and (Get-Annotation -Entity $_.vm -CustomAttribute $ca).Value -le $now} |&lt;/P&gt;&lt;P&gt;Remove-Snapshot -Confirm:$false&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Nov 2023 16:08:15 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Snapshot-Deletion/m-p/2993954#M113681</guid>
      <dc:creator>Pete_Howarth3</dc:creator>
      <dc:date>2023-11-02T16:08:15Z</dc:date>
    </item>
  </channel>
</rss>

