2013-04-09 60 views
1

我有下面,我一直在努力去工作,但目前不能。我希望它通过并获得netsh命令的输出,但我需要的只是检查三个输出。TCP烟囱命令通过Powershell

下面是一个命令输出,如果我只是运行它:

netsh int tcp show global | where {$_ -match ': disabled'} 


Receive-Side Scaling State   : disabled 
Chimney Offload State    : disabled 
Direct Cache Acess (DCA)   : disabled 
Receive Window Auto-Tuning Level : disabled 
ECN Capability      : disabled 
RFC 1323 Timestamps     : disabled 

Nowthen,如果我运行下面例如,为了获得“烟囱卸载状态”,并检查它被设置为禁用,那么它失败,并经过到ELSE statment称它设置为Enabled时,它不是...任何想法如何解决这个问题,请:

代码:

clear 
$netsh = netsh int tcp show global | where {$_ -match ': disabled'} 

if ($netsh -eq 'Chimney Offload State    : disabled') 
{ 
    Write-Host "TCP Chimney disabled" 
} 
else 
{ 
    Write-Host "TCP Chimney is ENABLED - WRONG!!!" 
} 

回答

5

另一种方法是将对象化的结果:

$pso = New-Object -TypeName PSObject 

netsh int tcp show global | where {$_ -match ':'} | foreach{ 
    $item = $_.Split(':') -replace '\s|-|\(|\)' 
    $pso | Add-Member -MemberType NoteProperty -Name $item[0] -Value $item[1] 
} 

if($pso.ChimneyOffloadState -eq 'disabled') 
{ 
    ... 
} 
+0

这是很好的!我会试试这个 - 看起来好多了。感谢Shay – lara400 2013-04-09 13:53:28

0

得到了它......它是添加一个 - 匹配的声明.. 。

if ($netsh -MATCH 'Chimney Offload State    : disabled')