PowerCLI

 View Only
  • 1.  Issue getting VM Snapshots Info

    Posted Sep 25, 2022 06:37 AM

    Hi,

    I would like to get the VM details where a particular snapshot with name (24Sep2022_Before_Patching) is missing. this way I can get to know where the particular snapshot is missed or not taken. Using the below, I am getting all the VMs with and without snapshots.

    Please help!

    Get-Folder POC | Get-VM | Get-Snapshot | Where-Object {$_.Name -ne "*24Sep2022_Before_Patching*" -and $_.VM.Guest.OSFullName -notmatch 'Microsoft'} | Select @{N='Folder';E={$_.Vm.Folder}},

    @{N='VM';E={$_.Vm.Name}},

    @{N='OS';E={$_.VM.Guest.OSFullName}},

    Name, Created, PowerState | ft -auto



  • 2.  RE: Issue getting VM Snapshots Info

    Posted Sep 25, 2022 07:04 AM

    I'm not sure I understand why you do $_.Name -ne "*24Sep2022_Before_Patching*" when you are looking for a snapshot named '24Sep2022_Before_Patching'.
    Shouldn't that -ne be an -eq?



  • 3.  RE: Issue getting VM Snapshots Info

    Posted Sep 25, 2022 08:26 AM

    LucD,

    I am using below script to take the snapshots but on few VMs the snapshot creation failed, hence I would like to know the VM names where Snapshot is not created.

    Import-Csv -Path .\vmnames.csv |
    ForEach-Object -Process {
    Get-VM -Name $_.VMName | New-Snapshot -Name "24Sep2022_Before_Patching" -Confirm:$false
    }



  • 4.  RE: Issue getting VM Snapshots Info

    Posted Sep 25, 2022 08:45 AM

    Ok, that could happen when you have VMs with multiple snapshots, including the "24Sep2022_Before_Patching" one.

    One way to avoid that could be

    Get-Folder POC | Get-VM | 
    Where-Object{$_.Guest.OSFullName -notmatch 'Microsoft'} |
    Where-Object {(Get-Snapshot -VM $_).Name -notcontains "24Sep2022_Before_Patching"} | 
    Get-Snapshot |
    Select @{N='Folder';E={$_.Vm.Folder}},
    @{N='VM';E={$_.Vm.Name}},
    @{N='OS';E={$_.VM.Guest.OSFullName}},
    Name, Created, PowerState | 
    Format-Table -auto

     



  • 5.  RE: Issue getting VM Snapshots Info

    Posted Sep 25, 2022 10:37 AM

    Hi LucD,

    That worked but while retrieving the VMs with particular Snapshot name, if a VM has multiple snapshots, it shows all the other snapshots Name along with requested particular snapshot. I dont want to get the other snapshot information which I am not requested from a VM.

    Get-Folder POC | Get-VM | Where-Object{$_.Guest.OSFullName -notmatch 'Microsoft'} | Where-Object {(Get-Snapshot -VM $_).Name -contains "24Sep2022_Before_Patching"} | Get-Snapshot | Select @{N='Folder';E={$_.Vm.Folder}}, @{N='VM';E={$_.Vm.Name}}, @{N='OS';E={$_.VM.Guest.OSFullName}}, Name, Created, PowerState | Format-Table -auto

     

    Example : I want to get the VM with particular Snapshot name only without getting any other snapshots info.

    ganapa2000_0-1664102086151.png

     

     

     



  • 6.  RE: Issue getting VM Snapshots Info

    Posted Sep 25, 2022 10:56 AM

    At the start you stated you wanted to get all the VMs that didn't have that particular snapshot.
    How can it show that snapshot when it is not there?



  • 7.  RE: Issue getting VM Snapshots Info

    Posted Sep 25, 2022 11:03 AM

    LucD,

    Below script which you helped, I am able to get the VMs which doesnt have particular Snapshot

    Get-Folder POC | Get-VM | 
    Where-Object{$_.Guest.OSFullName -notmatch 'Microsoft'} |
    Where-Object {(Get-Snapshot -VM $_).Name -notcontains "24Sep2022_Before_Patching"} | 
    Get-Snapshot |
    Select @{N='Folder';E={$_.Vm.Folder}},
    @{N='VM';E={$_.Vm.Name}},
    @{N='OS';E={$_.VM.Guest.OSFullName}},
    Name, Created, PowerState | 
    Format-Table -auto

     

    But If I want to get VMs with which has particular snapshot created, then I am getting the other snapshot information along with the snapshot, now how can I suppress other snapshot information of a VM and get only requested snapshot info - 24Sep2022_Before_Patching?

    Get-Folder POC | Get-VM | 
    Where-Object{$_.Guest.OSFullName -notmatch 'Microsoft'} |
    Where-Object {(Get-Snapshot -VM $_).Name -contains "24Sep2022_Before_Patching"} | 
    Get-Snapshot |
    Select @{N='Folder';E={$_.Vm.Folder}},
    @{N='VM';E={$_.Vm.Name}},
    @{N='OS';E={$_.VM.Guest.OSFullName}},
    Name, Created, PowerState | 
    Format-Table -auto

     



  • 8.  RE: Issue getting VM Snapshots Info
    Best Answer

    Posted Sep 25, 2022 11:16 AM

    Then you could do

    Get-Folder POC | Get-VM | 
    Where-Object{$_.Guest.OSFullName -notmatch 'Microsoft'} |
    Get-Snapshot |
    Where-Object {$_.Name -eq "24Sep2022_Before_Patching"} | 
    Select @{N='Folder';E={$_.Vm.Folder}},
    @{N='VM';E={$_.Vm.Name}},
    @{N='OS';E={$_.VM.Guest.OSFullName}},
    Name, Created, PowerState | 
    Format-Table -auto


  • 9.  RE: Issue getting VM Snapshots Info

    Posted Sep 25, 2022 11:23 AM

    That worked perfectly Thank you very much.