[get_snapshots] Added script
This commit is contained in:
parent
dcaf20173c
commit
1b69f27660
54
PowerShell/get_snapshots.ps1
Normal file
54
PowerShell/get_snapshots.ps1
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
#!/snap/bin/pwsh
|
||||||
|
|
||||||
|
# Prerequisites
|
||||||
|
Set-PowerCLIConfiguration -Scope User `
|
||||||
|
-ParticipateInCeip $false `
|
||||||
|
-confirm:$false | out-null
|
||||||
|
|
||||||
|
# Config section
|
||||||
|
$vcenter = "vcenter_server"
|
||||||
|
$user = "vcenter_user"
|
||||||
|
$password = "vcenter_user_password"
|
||||||
|
|
||||||
|
# Connect to vCenter
|
||||||
|
Set-PowerCLIConfiguration -InvalidCertificateAction ignore `
|
||||||
|
-confirm:$false | out-null
|
||||||
|
|
||||||
|
Connect-VIServer -Server $vcenter `
|
||||||
|
-User $user `
|
||||||
|
-Password $password | out-null
|
||||||
|
|
||||||
|
# Get snapshots
|
||||||
|
$results = @()
|
||||||
|
$vmsnapshots = Get-VM | `
|
||||||
|
Where {$_.Name -notmatch ".*replica.*" } | `
|
||||||
|
Get-Snapshot
|
||||||
|
|
||||||
|
if ($vmsnapshots.Name -ne $null) {
|
||||||
|
foreach ($snapshot in $vmsnapshots) {
|
||||||
|
$snapevent = Get-VIEvent -Entity $snapshot.VM `
|
||||||
|
-Types Info `
|
||||||
|
-Finish $snapshot.Created `
|
||||||
|
-MaxSamples 1 | `
|
||||||
|
Where-Object {$_.FullFormattedMessage -imatch 'Task: Create virtual machine snapshot'}
|
||||||
|
|
||||||
|
if ($snapevent -ne $null) {
|
||||||
|
$user = [string]$snapevent.UserName
|
||||||
|
$snapshot | Add-Member CreatedBy $user
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$snapshot | Add-Member CreatedBy '-- Unknown --'
|
||||||
|
}
|
||||||
|
$results = $results + $snapshot
|
||||||
|
}
|
||||||
|
|
||||||
|
$results = $results | Sort-Object -Property Created
|
||||||
|
$results | Format-Table -Property VM, `
|
||||||
|
CreatedBy, `
|
||||||
|
@{Label="CreatedOn"; Expression={Get-Date $_.Created -Format "dd.MM.yyyy"}}, `
|
||||||
|
Name
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Write-Output " Congratulations, there are no snapshots!"
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user