-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglm-windowsexporter-setup.ps1.template.dos
39 lines (32 loc) · 1.51 KB
/
glm-windowsexporter-setup.ps1.template.dos
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
# (C) Copyright 2024 Hewlett Packard Enterprise Development LP
# taken from https://kimconnect.com/powershell-install-windows-exporter/
# with local modifications
$fileName='windowsexporter.msi'
$stageFolder='C:\downloads\'
# Download the Windows Node Exporter .msi file
$msiFile=join-path $stageFolder $fileName
if(!(test-path $stageFolder)){mkdir $stageFolder}
Unblock-File -Path $msiFile
# Install using MSIEXEC
msiexec /i $msiFile ENABLED_COLLECTORS=os,cpu,cs,logical_disk,net,tcp,service,textfile LISTEN_PORT=45678 /passive
# Check whether product is installed
$serviceName='windows_exporter'
function checkUninstall($serviceName){
$cpuArchitecture32bitPointerSize=4
$path=if ([IntPtr]::Size -eq $cpuArchitecture32bitPointerSize) {
'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
}else{
@('HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*',
'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*')
}
Get-ItemProperty $path |.{process{ if ($_.DisplayName -eq $serviceName -and $_.UninstallString) { $_ } }} |
Select-Object DisplayName, Publisher, InstallDate, DisplayVersion, UninstallString
}
do{
sleep 5
$installed=checkUninstall $serviceName
}until($null -ne $installed)
# Set auto start and restart upon failures
$serviceName='windows_exporter'
& sc.exe failure $serviceName reset= 30 actions= restart/100000/restart/100000/""/300000
Set-Service -Name $serviceName -StartupType 'Automatic'