From 3de58c428cb94b7d34845f956ae84d61c8e31320 Mon Sep 17 00:00:00 2001
From: Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch>
Date: Tue, 13 Mar 2018 23:42:55 +0100
Subject: [PATCH] Add service account to local group during installation

Membership in the group "Performance Monitor Users" is required for the
CPU load monitoring to work, so add the service account to this group.

Refers to #40
---
 Scripts/Install-Service.ps1 | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/Scripts/Install-Service.ps1 b/Scripts/Install-Service.ps1
index 013ee8f..ae40ead 100644
--- a/Scripts/Install-Service.ps1
+++ b/Scripts/Install-Service.ps1
@@ -64,6 +64,24 @@ function Install-Service {
 }
 
 
+function Add-PerfMonGroupMember {
+    $GroupName = "Performance Monitor Users"
+    try {
+        Add-LocalGroupMember -Group $GroupName -Member $ServiceUser
+        Write-Host $("Successfully added user [$($ServiceUser)] to the local"
+                     "group [$($GroupName)].")
+    }
+    catch [Microsoft.PowerShell.Commands.MemberExistsException] {
+        Write-Host $("User [$($ServiceUser)] is already a member of the local"
+                     "group [$($GroupName)], no action required.")
+    }
+    catch {
+        Write-Host $("Adding user [$($ServiceUser)] to the local group"
+                     "[$($GroupName)] failed: $($_.Exception.Message)")
+    }
+}
+
+
 $ErrorActionPreference = "Stop"
 
 
@@ -87,6 +105,7 @@ if ($Service) {
 
 Copy-ServiceFiles
 Install-Service
+Add-PerfMonGroupMember
 
 Write-Host "`nWatching the service log file can be done like this:`n" `
     "`n> Get-Content -Wait -Tail 50 $($ServiceLog)`n"
-- 
GitLab