0
我需要一個Powershell腳本來讀取遠程計算機上的進程並將一些信息存儲到文本文件中。Powershell管道沒有存儲在變量中
我有這些查詢位於一個foreach循環thtough服務器陣列內:
if(($server.equals("DCOBB3")) -Or ($server.equals("DCOBB4")))
{
write-host "inside if with " $server
$w3wpresult = (get-wmiobject Win32_Process -filter "name like 'w3wp%'" -computername $server | select name, @{l= "Private Memory (GB)"; e={$_.privatepagecount/1gb}})
write-host $w3wpresult
$vmresult = (get-wmiobject Win32_Process -filter "name like 'w3wp%'" -computername $server | select name, @{l= "Virtual Memory (GB)"; e={$_.virtualsize/1gb}})
$vmMemory += $server + " @ " + $time + ": " + $vmresult + "`r`n"
$w3wpMemory += $server + " @ " + $time + ":" + $w3wpresult + "`r`n"
}
問題是,當服務器=「DCOBB4」的$w3wpresult
沒有被存儲在所述$w3wpMemory
對象內。
位於下面是查詢的輸出的示例:
inside if with DCOBB3
@{name=w3wp.exe; Private Memory (GB)=0.00959014892578125}
DCOBB4
inside if with DCOBB4
@{name=w3wp.exe; Private Memory (GB)=0.0100898742675781} @{name=w3wp.exe;
Private Memory (GB)=0.00747299194335938} @{name=w3wp.exe; Private Memory (GB)=0.0089874267578125}
---------- W3WP Memory Consumption ----------
AIDE500-V14 @ 0948:@{name=w3wp.exe; Private Memory (GB)=0.689697265625}
AIDE502-V12 @ 0948:@{name=w3wp.exe; Private Memory (GB)=0.0477447509765625}
AIWE80-005 @ 0948:@{name=w3wp.exe; Private Memory (GB)=0.932292938232422}
AIDE11-004 @ 0948:
AIDE11-005 @ 0948:
DCOBB3 @ 0948:@{name=w3wp.exe; Private Memory (GB)=0.00959014892578125}
DCOBB4 @ 0948
任何幫助是極大的讚賞, 謝謝!
'+ $ w3wpresult +' - >'+(($ w3wpresult |%{ 「$ _」}) - 加入')+' – PetSerAl
由於這是答案, 希望把它作爲所以我可以標記它? –