OK this SHOULD work but doesn't. I am attempting to evaluate disk usage with a PowerShell script. The component is set with a credential set that are a local admin. It is set to run locally on the poller and the check box for "Run the script under specified account:" is checked. The credentials are valid for the task.
It works perfectly the PowerShell ISE as the service account from the poller either with a correct command line or by un-commenting the Debug section. It fails as a component with the following error:
Error: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
Here is the script:
#requires -version 2
<#
.SYNOPSIS
Pulls all fixed disks and alerts on free space % issues. Warning is at the CL level and critical is 1/2 of that.
.DESCRIPTION
Run via SolarWinds' Server & Application (SAM) components.
.INPUTS
CL Arguments:
0 : ${Node.Caption} (Static, required, SolarWinds macro based argument)
1 : C: warning threshold (required)
2 : "Normal" drive threshold in GB. (required)
3 : Small drive size in GB. (required)
4 : Small drive threshold in GB. (required)
5 : Large drive size in GB. (required)
6 : Large drive threshold in GB. (required)
Sample CL:
${Node.Caption},10,15,2,5,750,5
.OUTPUTS
None.
.NOTES
Version: 1.0
Author: Michael Landman <Michael.Landman@FirstCitizens.com>
Creation Date: Jul 14, 2016
Purpose/Change: Initial script development.
#>
#----------------------------------------------------------[Initializations]-------------------------------------------------------
# set error action to silently continue
$ErrorActionPreference = "SilentlyContinue"
#----------------------------------------------------------[Declarations]----------------------------------------------------------
# script version
$scriptVersion = "1.0"
#----------------------------------------------------------[Init variables]--------------------------------------------------------
$server = $args[0];
[float]$cDriveThreshold = $args[1];
[float]$normalThreshold = $args[2];
$smallDriveSize = $args[3]*1024*1024*1024;
[float]$smallDriveThreshold = $arge[4];
$largDriveSize = $args[5]*1024*1024*1024;
[float]$largDrivethreshold = $args[6];
<#
#$debug = $true
#$sw = [Diagnostics.Stopwatch]::StartNew()
# debug variables
$server = [Remote_Server_Name}
[float]$cDriveThreshold = 10
[float]$normalThreshold = 15
$smallDriveSize = 2*1024*1024*1024;
[float]$smallDriveThreshold = 5;
$largDriveSize = 750*1024*1024*1024;
[float]$largDrivethreshold = 5;
#>
$msg = "";
$warning = 0;
$critical = 0;
$errorLevel = 0;
$freePercent = 0;
$state = "";
#----------------------------------------------------------[Functions]-------------------------------------------------------------
#----------------------------------------------------------[Execution]-------------------------------------------------------------
try{
$drives = get-WmiObject win32_logicaldisk -Computername $server | where driveType -eq 3 | where Size -NotLike $null
foreach ($drive in $drives)
{
if($drive.DeviceID -eq "C:")
{
$freePercent = (($drive.FreeSpace)/($drive.size)*100)
if($freePercent -le $cDriveThreshold/2)
{
$critical++;
$state = "critical"
$msg += "C: has {0:N2}% free and is {1}. " -f `
($freePercent, $state)
}
elseif($freePercent -le $cDriveThreshold)
{
$warning++;
$state = "warning";
$msg += "C: has {0:N2}% free and is {1}. " -f `
($freePercent, $state)
}
}
elseIf ($drive.Size -ge $largDriveSize) # Large Drive
{
$freePercent = (($drive.FreeSpace)/($drive.size)*100)
if($freePercent -le $largDrivethreshold/2)
{
$critical++;
$state = "critical"
$msg += "{0} has {1:N2}% free and is {2}. " -f `
($drive.DeviceID,$freePercent, $state)
}
elseif($freePercent -le $largDrivethreshold)
{
$warning++;
$state = "warning";
$msg += "{0} has {1:N2}% free and is {2}. " -f `
($drive.DeviceID,$freePercent, $state)
}
}
elseIf ($drive.Size -le $smallDriveSize) # Small Drive
{
$freePercent = (($drive.FreeSpace)/($drive.size)*100)
if($freePercent -le $smallDrivethreshold/2)
{
$critical++;
$state = "critical"
$msg += "{0} has {1:N2}% free and is {2}. " -f `
($drive.DeviceID,$freePercent, $state)
}
elseif($freePercent -le $smallDrivethreshold)
{
$warning++;
$state = "warning";
$msg += "{0} has {1:N2}% free and is {2}. " -f `
($drive.DeviceID,$freePercent, $state)
}
}
else
{
$freePercent = (($drive.FreeSpace)/($drive.size)*100)
if($freePercent -le $normalThreshold/2)
{
$critical++;
$state = "critical"
$msg += "{0} has {1:N2}% free and is {2}. " -f `
($drive.DeviceID,$freePercent, $state)
}
elseif($freePercent -le $normalThreshold)
{
$warning++;
$state = "warning";
$msg += "{0} has {1:N2}% free and is {2}. " -f `
($drive.DeviceID,$freePercent, $state)
}
}
}
if($critical -ne 0)
{
$errLevel = 2;
}
elseif($warning -ne 0)
{
$errLevel = 1;
}
ELSE
{
$msg = "All disks within normal space used amounts"
}
# report the message and statistic from above
write-host ("Message.DiskAlert: {0}" -f $msg | Out-string);
write-host ("Statistic.DiskAlert: {0}" -f $errLevel);
}
catch {
write-host ("Message.DiskAlert: Error: {0}" -f $_.Exception.Message);
write-host ("Statistic.DiskAlert: -1") ;
#This will set the component to DOWN
exit 1;
}
finally {
exit 0;
}
HELP...