Automation

 View Only
  • 1.  Combining two individual script into one single script

    Posted Feb 04, 2022 07:04 AM

    Hi Team,

    I have a script to identify vm which having snapshot more than one day as per below:

    $vm = Get-VM -Name 
    $snaps = Get-Snapshot -VM $vm | where { $_.Created -lt (Get-Date).AddDays(-1) }

    if ($snaps) {
    Write-Output "Snapshot detected"
    $snaps | Select-Object -Property @{N = 'VM'; E = { $_.VM.Name } },
    Name, Description, Created | Format-List
    } else {
    Write-Output "NO snapshot"
    '' | Select-Object -Property @{N = 'VM'; E = {$vm.Name} },
    @{N='Name';E={'No snapshot'}},@{N='Description';E={'na'}},@{N='Created';E={'na'}} |
    Format-List
    }

    ____________________________

    Secondly identify the snapshot Size as per below:

    function Get-SnapshotInfo
    {
    param(
    [VMware.Vim.VirtualMachineSnapshotTree]$Tree
    )

    $snapInfo = Get-View -Id $Tree.Snapshot
    $vm = Get-View -Id $Tree.VM

    $entry = $vm.LayoutEx.Snapshot | where{$_.Key -eq $Tree.Snapshot}
    $files = $vm.LayoutEx.File | where{($entry.Disk | %{$_.Chain[-1]}).FileKey -contains $_.Key}

    New-Object -TypeName PSObject -Property @{
    Name = $Tree.Name
    Created = $Tree.CreateTime
    SizeGB = [math]::Round(($files | Measure-Object -Property Size -Sum).Sum/1GB,2)
    }
    if($Tree.ChildSnapshotList){
    $Tree.ChildSnapshotList | ForEach-Object -Process {
    Get-SnapshotInfo -Tree $_
    }
    }
    }

    $vm = Get-VM -Name

    $vm.ExtensionData.Snapshot.RootSnapshotList |
    ForEach-Object -Process {
    Get-SnapshotInfo -Tree $_
    }

    ____________________________

    How may i combine both individual script into one.

    I need the Result to be display with below condition:

    1)Snapshot detected / No Snapshot detected

    2)List of VM Name detected with more than 1 day snapshot, along with the snapshot size



  • 2.  RE: Combining two individual script into one single script

    Posted Feb 04, 2022 07:38 AM

    Not sure why you want to combine that 2nd snippet.
    That walks the snapshot tree, and display for each snapshot the size.
    The size of a snapshot is already available in the object returned by Get-Snapshot.

    You could do something like this



  • 3.  RE: Combining two individual script into one single script

    Posted Mar 08, 2022 07:12 AM

    Hi Luc,

    At here

    Remove-Snapshot -Snapshot $_ -Confirm:$false

    How may we add state for each VM snapshot removal status

    The out put should be VM name, follow by Snapshot name, start time , finish time , percentage of completion, if it is still running then percentage of completion. state Removal Success or Fail, or Running in progress

     



  • 4.  RE: Combining two individual script into one single script

    Posted Mar 08, 2022 07:45 AM

    Something like this