【问题标题】:powershell escaping simple quote in counter namepowershell 转义计数器名称中的简单引号
【发布时间】:2018-04-12 17:57:57
【问题描述】:

我正在尝试获取我的一个 .NET 程序的计数器(使用“PathsWithInstance”)。 由于存在简单引号(法语操作系统版本),我似乎无法使用简单语法:

Get-Counter -Counter "\Mémoire CLR .NET(MyProgram)\Nombre d'octets dans tous les tas"

我尝试了各种转义策略,但总是收到错误消息,提示找不到指定的计数器。

我应该如何摆脱它?

我找到了这个临时解决方法:

(Get-Counter -Counter "\mémoire clr .net(MyProgram)\*").CounterSamples | Where-Object {$_.Path -match "Nombre d'octets dans tous les tas"}

编辑,由于 cmets: 所以我还是不明白为什么这不起作用:

Get-Counter -Counter "\mémoire clr .net(MyProgram)\nombre d'octets dans tous les tas"

并引发以下错误(抱歉,法语):

Get-Counter : Le compteur spécifié n’a pas été trouvé.
Au caractère Ligne:1 : 1
+ Get-Counter -Counter "\mémoire clr .net(MyProgram)\nombre d'octets ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidResult : (:) [Get-Counter], Exception
    + FullyQualifiedErrorId : CounterApiError,Microsoft.PowerShell.Commands.GetCounterCommand

虽然这确实有效:

(Get-Counter -Counter "\mémoire clr .net(MyProgram)\*").CounterSamples | Where-Object {$_.Path -match "nombre d'octets dans tous les tas"}

【问题讨论】:

  • 'this includes apostrophe''s' -> this includes apostrophe's ?
  • 谢谢@ConnorLSW 我知道双引号的诀窍,但在这种情况下它不起作用
  • 谢谢@Manu,但是我看到文档并尝试了反引号,双单引号,双引号中的简单引号,但仍然不起作用
  • @Christophe 有撇号问题。开玩笑;)

标签: powershell performancecounter


【解决方案1】:

对我来说,诀窍是用英文代替法文计数器。

我没有设法用 regedit 重命名它,而是像这里描述的那样替换了文件:https://www.zabbix.com/forum/zabbix-cookbook/7524-how-to-force-perfmon-counters-description-to-be-in-english?p=182838#post182838

重命名文件的脚本:

cd \windows\system32

move perfc00C.dat perfc00C_bak.dat
move perfd00C.dat perfd00C_bak.dat
move perfh00C.dat perfh00C_bak.dat
move perfi00C.dat perfi00C_bak.dat

copy perfc009.dat perfc00C.dat
copy perfd009.dat perfd00C.dat
copy perfh009.dat perfh00C.dat
copy perfi009.dat perfi00C.dat

【讨论】:

    猜你喜欢
    • 2023-04-02
    • 2015-07-16
    • 2013-01-28
    • 2014-01-24
    • 2020-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多