From 05de4d232e0a0808681761bff5b3409ccfeda1d6 Mon Sep 17 00:00:00 2001
From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch>
Date: Wed, 13 Dec 2017 16:46:01 +0100
Subject: [PATCH] Move sourcing of settings file below function defintion
 block.

This allows us to potentially use the logging functions.

Refers to #13
---
 Updater/Update-Service.ps1 | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/Updater/Update-Service.ps1 b/Updater/Update-Service.ps1
index 84784f2..e8d1384 100644
--- a/Updater/Update-Service.ps1
+++ b/Updater/Update-Service.ps1
@@ -10,17 +10,6 @@ Param(
     [Parameter(Mandatory=$True)][string] $UpdaterSettings
 )
 
-try {
-    . $UpdaterSettings
-}
-catch {
-    $ex = $_.Exception.Message
-    Write-Host "Error reading settings file: '$($UpdaterSettings)' [$($ex)]"
-    Exit
-}
-
-$Me = $MyInvocation.MyCommand -replace '.ps1'
-
 
 
 ###  function definitions  #####################################################
@@ -379,6 +368,19 @@ function Log-Info([string]$Message) {
 
 
 
+try {
+    . $UpdaterSettings
+}
+catch {
+    $ex = $_.Exception.Message
+    Write-Host "Error reading settings file: '$($UpdaterSettings)' [$($ex)]"
+    Exit
+}
+
+
+# NOTE: $MyInvocation is not available when run as ScheduledJob, so we have to
+# set a shortcut for our name explicitly ourselves here:
+$Me = "Update-Service"
 # first check if the service is installed and running at all
 Ensure-ServiceRunning $ServiceName
 
-- 
GitLab