jskfan
asked on
Powercli to Retrieve VM snapshots info from Datastore
Powercli to Retrieve VM snapshots info from Datastore
I need a Powercli command that retrieves the Snapshot of VMs not only the snapshots displayed on the Snapshot Manager , but also the ones that are not in the Snapshot Manager but they are still on the Datastore.
For now I need Powercli command to test it on a single VM , That I know it has snapshot on Datastore and that does not show in Snapshot Manager.
Thank you
I need a Powercli command that retrieves the Snapshot of VMs not only the snapshots displayed on the Snapshot Manager , but also the ones that are not in the Snapshot Manager but they are still on the Datastore.
For now I need Powercli command to test it on a single VM , That I know it has snapshot on Datastore and that does not show in Snapshot Manager.
Thank you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This will retrieve the VMs that have snapshot in the Datastore but not displayed on Snapshot Manager:
Get-VM | Where-Object {$_.Extensiondata.Runtime.Consolidat ionNeeded}
That checks if a consolidation is needed.
The problem here, is that Consolidation Warning is dumb! and the consolidation message/warning appears, because it's just a watcher/watchdog service for the presence of a snapshot file e.g. 0000x.vmdk on the datastore, it does not check if it's actually being used....
So you can get a Consolidation warning, and keep trying to "consolidate" and it never disappears.
This will retrieve VMs that have Snapshots in the Snapshot Manager. If it is not in the Snapshot Manager, but it is in the Datastore , it will not be retrieved.
get-vm | get-snapshot | Select-Object -Property vm,created,sizeGB,name,description
Correct, that's what I posted.
RV Tools, does a very good job, and so does Snap Watcher..
Set an Alarm in vCenter Server or Veeam One.
ASKER
The problem here, is that Consolidation Warning is dumb! and the consolidation message/warning appears, because it's just a watcher/watchdog service for the presence of a snapshot file e.g. 0000x.vmdk on the datastore, it does not check if it's actually being used....
for now I just wanted to retrieve the existence of the snapshots...
So you can get a Consolidation warning, and keep trying to "consolidate" and it never disappears.
Vmware admin I talked to had the same issue , per his statement he had to "stop vmware services on the ESX host " then run the consolidation.
I do not know what he meant by stopping Vmware services..... is that he migrated all the VMs from that host to another host and run consolidation ? would that make consolidation faster?
I have read online that cloning a VM will do the consolidation in an efficient way.
I know it is not Consolidation question...but as you see in Technology things can get too much involved
If you want to know the existence of Snapshots, set a vCenter Server ALARM and it will email, and flag the VM as Red Alert.
or invest in Snapwatcher.
or just find them at the ESXi console - find /vmfs/volumes/ -iname „*delta.vmdk”.
Later you will have to work out how to deal with them.
I'm afraid each and every snapshot issue is different, many different reasons why a snapshot occurred.
Not sure about that either...
I could present a 1 day Conference, on Snapshots alone.... as to why they occur, how they work, and don't work, and how to fix.
or invest in Snapwatcher.
or just find them at the ESXi console - find /vmfs/volumes/ -iname „*delta.vmdk”.
Later you will have to work out how to deal with them.
I'm afraid each and every snapshot issue is different, many different reasons why a snapshot occurred.
would that make consolidation faster?- No not really.
I have read online that cloning a VM will do the consolidation in an efficient way.
Not sure about that either...
I know it is not Consolidation question...but as you see in Technology things can get too much involved
I could present a 1 day Conference, on Snapshots alone.... as to why they occur, how they work, and don't work, and how to fix.
Hi,
This is my script that I use for find any snapshots older than (we set the minimum days of the snapshot to find), then have the option to delete them.
You can connect to a vCenter or a ESXi host. In all Clusters or just to a specific Cluster (remove comment to user any of different options).
Also the delete snapshot is commented, first list all snapshots, after if you agree, run again with the remove enable to enable all listed snapshots.
I use this script also to find any Snapshot left behind by Veeam Backup (that option is also commented).
Hope this can help.
This is my script that I use for find any snapshots older than (we set the minimum days of the snapshot to find), then have the option to delete them.
$vCenter = 'IP/FQDN'
$user = "user"
$pwd = "password"
#Connect-VIServer $vCenter
Connect-VIServer $vCenter -User $user -Password $pwd
### vCenter Server Name(FQDN)
$vCentName = [system.net.dns]::GetHostByAddress($vCenter).hostname
################################################
cls
$VMs = Get-VM
#$VMs = Get-Cluster "Cluster" | Get-VM
foreach ($VM in $VMs)
{
$AllSnapshots= Get-Snapshot -VM $VM
foreach ($Snapshot in $AllSnapshots)
{
#If ($Snapshot.Name -like “VEEAM BACKUP*” -and $Snapshot.Created -lt (Get-Date).AddDays(-1))
If ($Snapshot.Created -lt (Get-Date).AddDays(-5))
{
Write-Host "VM -> " $VM.Name,
Write-Host " Snapshot Name: " $Snapshot.Name
Write-Host " Snapshot Data: " $Snapshot.Created
Write-Host "Remove Snapshot :" $Snapshot.Name -ForegroundColor Red
# Remove-Snapshot -snapshot $Snapshot -confirm:$false -ErrorAction SilentlyContinue
Write-Host ""
#Start-Sleep -s 30
}
}
}
Disconnect-VIServer -Server $vCenter -Force -Confirm:$false
You can connect to a vCenter or a ESXi host. In all Clusters or just to a specific Cluster (remove comment to user any of different options).
Also the delete snapshot is commented, first list all snapshots, after if you agree, run again with the remove enable to enable all listed snapshots.
I use this script also to find any Snapshot left behind by Veeam Backup (that option is also commented).
Hope this can help.
ASKER
** is the script above Powershell Script ? I mean do I need to save it as .PS1
**Dos that script list the Snapshots that are not displayed on Snapshot Manager ?
***I would like to give a try your Script, if you can remove anything that has to do with modification or deletion. I want just to list the snapshots that are older than X days
**Dos that script list the Snapshots that are not displayed on Snapshot Manager ?
***I would like to give a try your Script, if you can remove anything that has to do with modification or deletion. I want just to list the snapshots that are older than X days
If you run the script in a script editor, you dont need to save into a ps1 file.
I use PowerGUI editor.
If not, then yes you should run this through a ps1 file.
All extra commands are commented, so is save to tun the script. Only if you want to delete etc., you will need do remove the comment %
I use PowerGUI editor.
If not, then yes you should run this through a ps1 file.
All extra commands are commented, so is save to tun the script. Only if you want to delete etc., you will need do remove the comment %
If you use PowerCLI to connect to vCenter Server, PowerCLI will display Snapshots Managed and maintained by vCenter Server.
The script posted still uses the command....
so... see my first post....
No.
If you want to list ALL snapshots on your data stores....
use find...
The script posted still uses the command....
Get-Snapshot -VM $VM
so... see my first post....
**Dos that script list the Snapshots that are not displayed on Snapshot Manager ?
No.
If you want to list ALL snapshots on your data stores....
use find...
ASKER
Thank you
No problems, glad to assist you with your Questions. Have a good day.
ASKER
Get-VM | Where-Object {$_.Extensiondata.Runtime.
This will retrieve VMs that have Snapshots in the Snapshot Manager. If it is not in the Snapshot Manager, but it is in the Datastore , it will not be retrieved.
get-vm | get-snapshot | Select-Object -Property vm,created,sizeGB,name,des