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
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
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
}
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
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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.
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?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
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
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That worked perfectly 🙂 Thank you very much.