function get-RPCPort{ param( $installpath) $content = Get-Content -Path ("$installpath\a5backup.properties") $property = $content -like 'service.rpc-server.localhost.port=*' $value = $property -split("=") return $value[1] } Function Set-Notifications{param( $installpath, $to, $from, $subjectprefix, $smtpserver, $port, $tlsversion = "TLSv1", $username, $password,$secure,$useAuth ) $json = @" { "version":1, "notifications":{ "ROLLUP":{ "enabled":false, "notify":"WARNINGS", "attachments":{ "enabled":true, "files":[ "FULL" ] } }, "ARCHIVING":{ "enabled":false, "notify":"WARNINGS", "attachments":{ "enabled":true, "files":[ "FULL" ] } }, "RESTORE":{ "enabled":false, "notify":"WARNINGS", "attachments":{ "enabled":true, "files":[ "FULL" ] } }, "BACKUP":{ "enabled":true, "notify":"WARNINGS", "attachments":{ "enabled":true, "files":[ "FULL" ] } }, "ANALYSIS":{ "enabled":false, "notify":"WARNINGS", "attachments":{ "enabled":true, "files":[ "FULL" ] } } }, "to":"$to", "from":"$from", "subjectPrefix":"$Subjectprefix", "server":"$smtpserver", "port":$smtpport, "secure":$secure, "tlsVersion":"$tlsversion", "useAuth":$useAuth, "authentication": { "credentials": { "username": "$username", "password": "$password" } }, "maximumAttachmentSize":10485760 } "@ #$json = @" #{"speedLimits" : {"1": $limit1, "2": $limit2, "3": $limit3, "4": $limit4, "5": $limit5, "6": $limit6 } } #"@ Write-Output $json $port = get-RPCPort -installpath $installpath $TaskID = Invoke-RestMethod -Method post -uri http://localhost:$port/api/v1/notifications/email -body $json -ContentType "application/json" #$done #while($done.type -ne "Completed"){ #$done = Task-Status -TaskId $TaskID #} #$Uri = "http://localhost:$port/v1/tasks/$taskID/result" #$result = Invoke-RestMethod -Method get -uri $uri #$result } Function Get-Notifications { param($installpath) $port = get-RPCPort -installpath $installpath $Response = Invoke-RestMethod -Method get -uri http://localhost:$port/api/v1/notifications/email -ContentType "application/json" $jsonresponse = ConvertTo-Json -InputObject $Response Write-Output $jsonresponse #$done #while($done.type -ne "Completed"){ #$done = Task-Status -TaskId $TaskID #} #$Uri = "http://localhost:$port/v1/tasks/$taskID/result" #$result = Invoke-RestMethod -Method get -uri $uri #$result } # script starts here # set values to use $to = "helpdesk@customer.com; support@customer.com" $from = "alerts@customer.com" $subjectprefix = "Redstor Notification" $smtpserver = "smtp.office365.com" $smtpport = "587" $username = "smtpuser@customer.com" $password = "mypass" $secure = $true $useAuth = $true # find the installed ESE service # set the path location used to this $servicename = "RedstorPro-ESE" $foundservice = Get-Service -Name $servicename if( $foundservice ) { # work through the services, get the image path $SerName = $foundservice.Name # Get the path from the service name $BinPath = (Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\services\$SerName" ImagePath) | Select ImagePath # Write-Output "ImagePath Found: " $BinPath # get the path for the service $BatPathString = $BinPath.ImagePath if( ($BatPathString -like "*A5Backup64.exe*") -or ($BatPathString -like "*A5Backup.exe*")) { # remove the " -start" bit from the end of the string $pos = $BatPathString.IndexOf(" -start") $BatPathString = $BatPathString.Substring(1, ($pos -2)) # now want to remove the executable filename $pos = $BatPathString.LastIndexOf("\") $BatPathString = $BatPathString.Substring(0,$pos) # now set the values using API calls Set-Notifications -installpath $BatPathString -to $to -from $from -subjectprefix $subjectprefix -smtpserver $smtpserver -port $smtpport -username $username -password $password } }