forked from RussellSageCollege/VeeamSlackNotifications
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSlackNotificationBootstrap.ps1
30 lines (26 loc) · 1.33 KB
/
SlackNotificationBootstrap.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
####################
# Import Functions #
####################
Import-Module "$PSScriptRoot\Helpers"
# Get the config from our config file
$config = (Get-Content "$PSScriptRoot\config\vsn.json") -Join "`n" | ConvertFrom-Json
# Should we log?
if($config.debug_log) {
Start-Logging "$PSScriptRoot\log\debug.log"
}
# 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
$job = Get-VBRJob | ?{$parentcmd -like "*"+$_.Id.ToString()+"*"}
# Get the Veeam session
$session = Get-VBRBackupSession | ?{($_.OrigJobName -eq $job.Name) -and ($parentcmd -like "*"+$_.Id.ToString()+"*")}
# Store the ID and Job Name
$Id = '"' + $session.Id.ToString().ToString().Trim() + '"'
$JobName = '"' + $session.OrigJobName.ToString().Trim() + '"'
# Build argument string
$powershellArguments = "-file $PSScriptRoot\SlackVeeamAlertSender.ps1", "-JobName $JobName", "-Id $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
Start-Process -FilePath "powershell" -Verb runAs -ArgumentList $powershellArguments -WindowStyle hidden