Skip to content

Instantly share code, notes, and snippets.

@joeypiccola
Created August 27, 2018 19:42
Show Gist options
  • Save joeypiccola/eaf4db415a34da84abc886f2d1c381f3 to your computer and use it in GitHub Desktop.
Save joeypiccola/eaf4db415a34da84abc886f2d1c381f3 to your computer and use it in GitHub Desktop.
Function Send-PushOver {
[CmdletBinding()]
Param (
[Parameter()]
[string]$Message,
[string]$Title,
[string]$User,
[string]$Token,
[uri]$Uri
)
$parameters = @{
token = $token
user = $user
message = $Message
title = $title
}
$parameters | Invoke-RestMethod -Method Post -Uri $Uri
}
Connect-VIServer -Server 'vcenter' -Password '*' -User '*'
$vms = Get-VM
$vmsnaps = @()
foreach ($vm in $vms) {
$snapshots = Get-Snapshot -VM $vm
if ($snapshots.count -gt 0) {
$i = 1
$message = @(); $pm = $null
$message += "$($snapshots.count)x snapshots detected on $($vm.Name)`n-------------`n"
Write-Host -ForegroundColor Magenta "$($vm.name) has $($snapshots.count)x snapshots"
foreach ($snapshot in $snapshots) {
Write-Host -ForegroundColor Cyan "$($vm.Name): $($snapshot.Name) (Created: $($snapshot.Created))"
$message += "$i`: Name: $($snapshot.Name) (Created: $($snapshot.Created))`n`n"
$i++
}
$pm = @"
$message
"@
$SendPushoverSplat = @{
'Message' = $pm
'Title' = 'vCenter Snapshot Alert'
'User' = '*'
'Token' = '*'
'Uri' = "https://api.pushover.net/1/messages.json"
}
Send-PushOver @SendPushoverSplat
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment