-
Notifications
You must be signed in to change notification settings - Fork 0
/
notify-hyper-v-restarted.ps1
38 lines (34 loc) · 1.04 KB
/
notify-hyper-v-restarted.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function send-notify {
Add-Type -AssemblyName System.Windows.Forms
$global:balloon = New-Object System.Windows.Forms.NotifyIcon
$path = (Get-Process -id $pid).Path
$balloon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path)
$balloon.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Warning
$balloon.BalloonTipText = 'Hyper-v VM restarted'
$balloon.BalloonTipTitle = "Hyper-v VM restarted"
$balloon.Visible = $true
$balloon.ShowBalloonTip(5000)
}
function get-time($name) {
return Get-VM $name | Select-Object -ExpandProperty Uptime
}
param(
$name
)
$startTime = get-time $name
$val = $True
Write-Host "time is: $startTime"
while ($val -eq $True) {
$partialTime = get-time $name
if ($startTime -ge ($partialTime)) {
Write-Host "uptime: $($partialTime)"
send-notify
# $val = $False
}
else {
Write-Host "uptime: $($partialTime)"
# $val = $False
}
$startTime = $partialTime
Start-Sleep -Seconds 2
}