2012-10-12 47 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有關爲遠程命令傳遞參數的鏈接。

希望這會有所幫助。