2012-10-12 49 views
1

我尝试从远程计算机使用以下“性能计数器代码”。 getAll(counters)返回一个String数组,其中包含我想要获得的所有性能计数器Pathes。但它不起作用。具有多个计数器的C#远程性能计数器

结果不包含任何内容,调用该命令后。 任何想法为什么这不工作,因为它应该?

Runspace runspace = RunspaceFactory.CreateRunspace(); 
runspace.Open(); 

Pipeline pipeline = runspace.CreatePipeline(); 

pipeline.Commands.AddScript(@"$sessions = New-PSSession -ComputerName " + serverName + Environment.NewLine 
    + @"Invoke-Command -session $sessions -ScriptBlock {Get-Counter -counter " + getAll(counterNames) + " }" + Environment.NewLine 
    + "Remove-PSSession -Session $sessions" + Environment.NewLine 
    + "exit" + Environment.NewLine + "exit" + Environment.NewLine); 


result = pipeline.Invoke(); 

对于实例GETALL返回此

getAll(counterNames) 
{string[2]} 
    [0]: "\\Memory\\Available Bytes" 
    [1]: "\\Processor(_Total)\\% Processor Time" 

我使用本地Power Shell命令这一点,它工作正常与GETALL

psh.AddCommand("get-counter"); 
        psh.AddParameter("computername", serverName); 
        psh.AddParameter("counter", getAll(counterNames)); 

        result = this.PowershellInvoke(psh); 

但我需要远程计算机的一个解决方案,我需要一个会话。

+0

您是否尝试过使用Windows操作系统提供的'Logman.exe'? –

+0

当我用例如“\ Memory \ Available Bytes”,“\ Processor(_Total)\%Processor Time”替换getAll(counterName)时,它正在工作。所以从StringArray到PowerShell命令的转换有什么问题 –

+0

getAll()函数做了什么?你能分享吗? –

回答

0

请检查这些链接: - 有关发送文件到远程PS会话,他creates a byte array用来存放文件的内容

  1. This联系洽谈。

  2. This有关为远程命令传递参数的链接。

希望这会有所帮助。