Powershell:
## Install WMI Exporter
## Displays the error message and stops executing.
$ErrorActionPreference="Stop";`
## Test permissions
If(-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent() ).IsInRole( [Security.Principal.WindowsBuiltInRole] “Administrator”)){ throw "Run command in an administrator PowerShell prompt"};`
## Test version Powershell
If($PSVersionTable.PSVersion -lt (New-Object System.Version("3.0"))){ throw "The minimum version of Windows PowerShell that is required by the script (3.0) does not match the currently running version of Windows PowerShell." };`
## Create DIR
If(-NOT (Test-Path $env:SystemDrive\'rdbtools')){mkdir $env:SystemDrive\'rdbtools'};`
## CD
Set-Location $env:SystemDrive\'rdbtools';`
## Download exporter
$Uri='https://github.com/martinlindhe/wmi_exporter/releases/download/v0.11.0/wmi_exporter-0.11.0-amd64.msi';`
#$Uri='https://rdbit.ru/distr/wmi.msi';`
$Exporter = $env:SystemDrive + '\rdbtools\wmi.msi';`
Invoke-WebRequest -Uri $Uri -OutFile $Exporter ;`
## Uninstall old version
$MyApp = Get-WmiObject -Class Win32_Product | Where-Object{$_.Name -eq "WMI Exporter"} ;`
$MyApp.Uninstall() ;`
## Shoce options and Install
$ArgumentList='/i ' + $Exporter + ' ENABLED_COLLECTORS=os,cpu,cs,logical_disk,memory,net,system /quiet';` ## defailt
If( Get-WindowsFeature -Name Hyper-V | Where Installed) { $ArgumentList='/i ' + $Exporter + ' ENABLED_COLLECTORS=os,cpu,cs,logical_disk,hyperv,memory,net,system /quiet'};`
If( Get-WindowsFeature -Name AD-Domain-Services | Where Installed) { $ArgumentList='/i ' + $Exporter + ' ENABLED_COLLECTORS=os,cpu,cs,ad,logical_disk,memory,net,system /quiet'}; `
Write-Output $ArgumentList;`
Start-Process msiexec.exe -Wait -ArgumentList $ArgumentList;`
## Firewall rule
If( Get-WindowsFeature -Name Hyper-V | Where Installed ) { netsh advfirewall firewall add rule name="Prometeus" dir=in action=allow protocol=TCP localport=9182 remote=8.117.19.95 };
Inline Powershell:
$ErrorActionPreference="Stop";If(-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent() ).IsInRole( [Security.Principal.WindowsBuiltInRole] “Administrator”)){ throw "Run command in an administrator PowerShell prompt"};If($PSVersionTable.PSVersion -lt (New-Object System.Version("3.0"))){ throw "The minimum version of Windows PowerShell that is required by the script (3.0) does not match the currently running version of Windows PowerShell." };If(-NOT (Test-Path $env:SystemDrive\'rdbtools')){mkdir $env:SystemDrive\'rdbtools'};Set-Location $env:SystemDrive\'rdbtools';$Uri='https://github.com/martinlindhe/wmi_exporter/releases/download/v0.11.0/wmi_exporter-0.11.0-amd64.msi';$Exporter = $env:SystemDrive + '\rdbtools\wmi.msi';Invoke-WebRequest -Uri $Uri -OutFile $Exporter ;$MyApp = Get-WmiObject -Class Win32_Product | Where-Object{$_.Name -eq "WMI Exporter"};$MyApp.Uninstall();$ArgumentList='/i ' + $Exporter + ' ENABLED_COLLECTORS=os,cpu,cs,logical_disk,memory,net,system /quiet';If( Get-WindowsFeature -Name Hyper-V | Where Installed) { $ArgumentList='/i ' + $Exporter + ' ENABLED_COLLECTORS=os,cpu,cs,logical_disk,hyperv,memory,net,system /quiet'};If( Get-WindowsFeature -Name AD-Domain-Services | Where Installed) { $ArgumentList='/i ' + $Exporter + ' ENABLED_COLLECTORS=os,cpu,cs,ad,logical_disk,memory,net,system /quiet'};Write-Output $ArgumentList;Start-Process msiexec.exe -Wait -ArgumentList $ArgumentList;If( Get-WindowsFeature -Name Hyper-V | Where Installed ) { netsh advfirewall firewall add rule name="Prometeus" dir=in action=allow protocol=TCP localport=9182 remote=138.197.190.95 };
0 Комментарии