forked from RussellSageCollege/VeeamSlackNotifications
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Start-VeeamTeamsNotification.ps1
44 lines (27 loc) · 1.28 KB
/
Start-VeeamTeamsNotification.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
39
40
41
42
43
44
# Import Helper Functions
Import-Module "$PSScriptRoot\Helpers"
# Get the config from our config file
$Config = Get-Content -Path "$PSScriptRoot\config\VeeamTeamsNotificationConfig.json" -Raw | ConvertFrom-Json
# Should we log?
if( $Config.DebugEnable ) {
Start-Logging -Path $Config.DebugPath
}
# Add Veeam commands
Add-PSSnapin VeeamPSSnapin
# Get Veeam job from parent process
$ParentPID = ( Get-WmiObject Win32_Process -Filter "ProcessID='$PID'" ).ParentProcessId.ToString()
$ParentCmd = ( Get-WmiObject Win32_Process -Filter "ProcessID='$ParentPID'" ).CommandLine
$BackupJob = Get-VBRJob |
Where-Object { $ParentCmd -match $_.Id }
# Get the Veeam session
$Session = Get-VBRBackupSession |
Where-Object { ( $_.OrigJobName -eq $BackupJob.Name ) -and ( $ParentCmd -match $_.Id ) }
# Start a new new script in a new process with some of the information gathered her
# Doing this allows Veeam to finish the current session so information on the job's status can be read
$Process = @{
FilePath = 'powershell.exe'
ArgumentList = "-ExecutionPolicy ByPass -Command ""& '$PSScriptRoot\Send-VeeamTeamsNotification.ps1' -Id '$($Session.Id)' -OrigJobName '$($Session.OrigJobName)'"""
Verb = 'RunAs'
WindowStyle = 'Hidden'
}
Start-Process @Process