我需要一个Powershell脚本,它在远程计算机上读取进程并将一些信息存储到文本文件中。
我将这些查询放在一个ForEach循环的服务器阵列中:
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
非常感谢任何帮助, 谢谢!
答案 0 :(得分:1)
将$(document).ready(function(){
$.fn.Restrictions = function () {
if($('#restriciton_cb').checked)
{
$('#RestrictionDiv').fadeIn('slow');
}else{
$('#RestrictionDiv').fadeOut('slow');
}
};
$('#restriciton_cb').change(function(){
fn.Restrictions;
});
fn.Restrictions;
});
转为[PSCustomObject]
时会有一些奇怪的行为。在某些情况下(特别是,当[string]
是数组的一部分时),它会导致空字符串而不是所需的值:
[PSCustomObject]
作为解决方法,您可以将$a=[PSCustomObject]@{a=1}
$a.ToString() # return ""
$a.PSObject.ToString() # return "@{a=1}"
[string]$a # return "@{a=1}"
"$a" # return "@{a=1}"
"$(2,$a,3)" # return "2 3"
$a-join',' # return "@{a=1}"
(2,$a,3)-join',' # return "2,,3"
逐个转为[PSCustomObject]
,然后加入结果:
[string]