Delete Multiple Virtual Machine Snapshots Older Than Specific Days

Поделиться
HTML-код
  • Опубликовано: 20 авг 2024
  • In this video you will learn how to get and delete snapshot from vCenter Virtual Machine with Older Than or Greater Than specific days. Suppose you want to delete snapshot on specific virtual machine 7 days earlier or 7 days older, you can do that by using this script.
    also, I have explained how to use this filter in Script so you can easily understand, please let me know if you have any query.
    ========================================================
    ##Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $false
    $Credential = Get-Credential -Message "Enter Login Credential"
    $vCenter = Read-Host -Prompt "Enter vCenter Name"
    Connect-VIServer -Server $vCenter -Credential $Credential
    $DaysOLD = Read-Host "Enter days count to get OLDER Snapshot"
    $VMs = Get-Content C:\Scripts\Allservers.txt
    foreach ($vm in $VMs){
    Invoke-Command {
    Get-VM $vm | Get-Snapshot | Where {$_.Created -gt (Get-Date).AddDays(-$DaysOLD)} | Select-Object VM, Name, Created | Export-Csv C:\Temp\Snapshot.csv -Append
    Get-VM $vm | Get-Snapshot | Where {$_.Created -gt (Get-Date).AddDays(-$DaysOLD)} | Remove-Snapshot -Confirm:$false
    }}
    ========================================================
    How To Create File Selection Dialog Box in PowerShell
    • How To Create File Sel...
    Add User/Group To The Local Administrators/RDP Group On Multiple Computers
    • Add User/Group To The ...
    Get Windows Updates list from Remote Computer
    • Get Windows Updates li...
    PowerShell Remotely Uninstall Software from Multiple Computers
    • PowerShell Remotely Un...
    PowerShell Search Specific KB Status on Remote Computers
    • PowerShell Search Inst...
    PowerShell Script to Connect Multiple Server's Remote Session
    • PowerShell Script to C...
    PowerCLI Script to power ON dedicated VMs listed in a text file
    • PowerCLI Script to pow...
    PowerCLI Script to power Off dedicated VMs listed in a text file
    • PowerCLI Script to pow...
    Delete Snapshot's from Multiple Virtual Machines
    • Delete Snapshot's from...
    Create Snapshot on Multiple Virtual Machine
    • Create Snapshot on Mul...
    How can I check if a port is open remotely
    • Identify if Windows TC...
    Installing software remotely on Multiple "Workgroup" Computers
    • Installing software re...
    PowerShell Installing software remotely on Multiple Computers
    • PowerShell Installing ...
    Unable to move OU in Active Directory (Access is denied)
    • Unable to move OU in A...
    PowerShell Installing software remotely on Multiple Computers
    • PowerShell Installing ...
    Get Multiple Services Status Remotely | Remotely Start or Stop Services
    • Get Multiple Services ...
    Get Date and Time from Multiple Remote Computers
    • Get Date and Time from...
    PowerCLI - How to get HA restarted VM's List
    • PowerCLI - How to get ...
    Get-Childitem - Search file on Local and Remote Computers
    • Get-Childitem - Search...
    Remotely Create Update Delete Registry Key on Multiple Computers
    • Remotely Create Update...
    Get service status from remote server's using PowerShell
    • Get service status fro...

Комментарии • 5

  • @syedfarooq3208
    @syedfarooq3208 Год назад

    If you Share me how to install VM model's because sometime script unable to fetch Data 7.0 version. Any solution available

  • @syedfarooq3208
    @syedfarooq3208 Год назад

    Hi Sir, Could you please share me script auto delete snapshot and more than 3 days old snapshots. And excluded the specified vm snapshot if customer wants. And connect to multiple VCENTER.

    • @syedfarooq3208
      @syedfarooq3208 Год назад +1

      Waiting for update sir please

    • @SwapnilInfotech
      @SwapnilInfotech  Год назад +1

      You can user below script to delete the snapshot older than 3 days and also you can add vm's to ignore snapshot deletion. Deletion command I have marked in comment so if you run the script, you will only get result unless you remove ## from the command. It will ignore the VM that you added in $vmsToIgnore variable. I dont have multiple VC in lab so i cannot test that. hope you find it well.
      ===========================================
      $Credential = Get-Credential -Message "Enter Login Credential"
      $vCenter = Read-Host -Prompt "Enter vCenter Name"
      Connect-VIServer -Server $vCenter -Credential $Credential
      $DaysOLD = Read-Host "Enter days count to get OLDER Snapshot"
      $vmsToIgnore = gc C:\Scripts\IgnoreVM.txt
      Get-VM | ForEach-Object {
      if ($vmsToIgnore -contains $_.Name){
      #No Action for this VM's
      }else{
      Get-Snapshot $_ | Where {$_.Created -lt (Get-Date).AddDays(-$DaysOLD)} | Select-Object vm, VmId, Name, Description, SizeGB, Created | ft -AutoSize
      ## Below command will delete the snapshot so Only enable below command when you are sure, you are getting result as expected
      ##Get-Snapshot $_ | Where {$_.Created -lt (Get-Date).AddDays(-$DaysOLD)} | Remove-Snapshot -Confirm:$false
      }
      }
      ===========================================

    • @syedfarooq3208
      @syedfarooq3208 Год назад

      @@SwapnilInfotech Thanks a lot sir, I will check