Powershell Datapoints
Sorry for spamming but i cant find a way to edit my post and i can reply to my post to add infor
My Second Question is regarding the configuration of datapoints.
Can some give me an example how to configure datapoints to pick up my values. Currently i tried this.
Metric type Raw metric Post Processor Alert threshold
IsAutoManaged gauge output keyvalue(IsAutoManaged)
IsOnCDrive gauge output keyvalue(IsOnCDrive)
OtherFilesExist gauge output keyvalue(OtherFilesExist)
PageFileDrive gauge output keyvalue(PageFileDrive)
My Test Datasource
# Clears the CLI of any text
Clear-Host
# Clears memory of all previous variables
Remove-Variable * -ErrorAction SilentlyContinue
#------------------------------------------------------------------------------------------------------------
# Initialize Variables
$TargetHostName = '##SYSTEM.SYSNAME##' + '.' + '##SYSTEM.DOMAIN##'
$CollectorHostName = $env:computername
$TargetUserName = '##wmi.user##'
$TargetPassword = '##wmi.pass##'
$DebugMode = $false$ScriptBlock = {
param (
[bool]$Debug
)
# Get pagefile information
$pageFileInfo = Get-CimInstance -Class Win32_PageFileUsage | Select-Object *
$CompSysResults = Get-CimInstance win32_computersystem -Namespace 'root\cimv2'# Initialize variables
$pageFileDrive = ""
$isOnC = $false
$isAuto = $false
$otherFilesExist = $falseif ($pageFileInfo) {
$pageFilePath = $pageFileInfo.Name
$pageFileDrive = Split-Path -Path $pageFilePath -Qualifier# Check if pagefile is on C: drive
$isOnC = $pageFileDrive -eq "C:"# Check if pagefile size is set to auto
$isAuto = $CompSysResults.AutomaticManagedPagefile# Output results
Write-Host "PageFileDrive=$pageFileDrive"
Write-Host "IsOnCDrive=$isOnC"
Write-Host "IsAutoManaged=$isAuto"# Check for other files/folders on pagefile drive
if ($pageFileDrive -eq "D:") {
$otherItems = Get-ChildItem -Path $pageFileDrive -Force | Where-Object { $_.FullName -ne $pageFilePath }
$otherFilesExist = $otherItems.Count -gt 0
Write-Host "OtherFilesExist=$otherFilesExist"
}}
}
if ($TargetHostName -eq $CollectorHostName)
{
Invoke-Command -ScriptBlock $ScriptBlock -ArgumentList @($DebugMode,$Instance)
}
else
{
#If WMI creds undefined - invoke remote command without creds, if not - create credential object and use it for authorization
if (($TargetUserName -Match "wmi.user" -and $TargetPassword -Match "wmi.pass") -or
($TargetUserName -eq "" -and $TargetPassword -eq ""))
{
Invoke-Command -ComputerName $TargetHostName -ScriptBlock $ScriptBlock -ArgumentList @($DebugMode,$Instance)
}
else
{
$TargetCredentials = New-Object System.Management.Automation.PSCredential ($TargetUserName, $(ConvertTo-SecureString $TargetPassword -AsPlainText -Force))
Invoke-Command -ComputerName $TargetHostName -ScriptBlock $ScriptBlock -Credential $TargetCredentials -ArgumentList @($DebugMode,$Instance)
}
}Exit 0
Windows Cert
$Instance = '##WILDVALUE##'
$TargetHostName = '##SYSTEM.SYSNAME##' + '.' + '##SYSTEM.DOMAIN##'
$CollectorHostName = $env:computername
$TargetUserName = '##wmi.user##'
$TargetPassword = '##wmi.pass##'
$DebugMode = $false$ScriptBlock = {
param (
[bool]$Debug,
[String]$SerialNumber
)
if ($Cert = Get-ChildItem -Path cert:LocalMachine -Recurse | Where-Object { $_.SerialNumber -eq $SerialNumber } | Sort-Object -Unique) {
$TimeSpan = New-TimeSpan -Start (Get-Date) -End $Cert.NotAfter
$DaysLeft = $TimeSpan.Days
Write-Host "DaysLeft=$DaysLeft"
}
}if ($TargetHostName -eq $CollectorHostName)
{
Invoke-Command -ScriptBlock $ScriptBlock -ArgumentList @($DebugMode,$Instance)
}
else
{
#If WMI creds undefined - invoke remote command without creds, if not - create credential object and use it for authorization
if (($TargetUserName -Match "wmi.user" -and $TargetPassword -Match "wmi.pass") -or
($TargetUserName -eq "" -and $TargetPassword -eq ""))
{
Invoke-Command -ComputerName $TargetHostName -ScriptBlock $ScriptBlock -ArgumentList @($DebugMode,$Instance)
}
else
{
$TargetCredentials = New-Object System.Management.Automation.PSCredential ($TargetUserName, $(ConvertTo-SecureString $TargetPassword -AsPlainText -Force))
Invoke-Command -ComputerName $TargetHostName -ScriptBlock $ScriptBlock -Credential $TargetCredentials -ArgumentList @($DebugMode,$Instance)
}
}Exit 0