You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

NCPA执行带参数PowerShell脚本异常:Get-Counter报错c0000bc4

Fixing Get-Counter Error c0000bc4 When Passing Parameters via NCPA

Hey there, let's tackle that annoying Get-Counter error you're hitting. The issue boils down to how your counter path parameter is being parsed when passed from Nagios to your PowerShell script via NCPA—here's how to fix it:

Why This Happens

When you call the script with -a "'\Processor Information(_Total)\% Processor Time'", the nested single quotes are causing problems. By the time PowerShell receives the parameter, $args[0] isn't the clean counter path you expect—it's likely wrapped in extra single quotes (like '\Processor Information(_Total)\% Processor Time'). Since there's no performance counter with those surrounding quotes, Get-Counter throws the c0000bc4 error, exactly as it would for a non-existent path.

Quick Fixes to Try

1. Clean Up the Parameter in Your PowerShell Script

Add a line to strip any unwanted surrounding quotes from the incoming parameter. This is a robust fix that handles any quote mishaps from the call side:

# Trim surrounding single quotes from the incoming counter path
$count = $args[0].Trim("'")
$warn = 1500
$crit = 2000
$Data = Get-Counter -Counter $count
$Raw = $Data.CounterSamples.CookedValue
Write-Host "$Raw | 'Counter'=$Raw;$warn;$crit;0;3000"
if ($Raw -gt $crit) { exit 2 }
elif ($Raw -gt $warn) { exit 1 }
else { exit 0 }

2. Adjust the Nagios Call Command

Fix the quote structure in your check_ncpa.py call so the counter path is passed cleanly. Use a single set of single quotes to wrap the parameter (this prevents the shell from parsing special characters like %):

/usr/local/nagios/libexec/check_ncpa.py -H 192.168.**.** -t 'randomkeystringstuff' -P 5693 -M plugins/counter.ps1 -a '\Processor Information(_Total)\% Processor Time'

3. Verify the Received Parameter (For Debugging)

If you're still unsure, add a debug line to your script to print exactly what parameter PowerShell is getting:

Write-Host "Received counter path: [$count]"

Run the Nagios call again and check the output—this will confirm if extra quotes are the culprit.

Why Direct Assignment Works

When you hardcode $count = "\Processor Information(_Total)\% Processor Time" in the script, PowerShell gets the exact, unmodified counter path without any extra quoting. The problem only arises when the parameter is passed through multiple layers (shell → NCPA → PowerShell) which can mangle quote formatting.

内容的提问来源于stack exchange,提问作者Domsch

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 09:11:33