netsh 结果到 PowerShell 对象 [英] netsh result to a PowerShell object
本文介绍了netsh 结果到 PowerShell 对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试通过 PowerShell 使用 NETSH.我想查看此命令的结果,例如对象,但 netsh 返回一个字符串:
I am trying to work with NETSH from PowerShell. I want see a result from this command such as an object, but netsh returns a string:
netsh wlan show hostednetwork | Get-Member
TypeName: System.String
...
我的脚本必须在相当本地化的系统上工作,而且我不能使用 -match 将字符串直接解析为对象.
My script must work on system with rather localization, and I can't use -match for parsing a string to an object directly.
我该如何解决我的问题?
How I can solve my trouble?
推荐答案
$netshResult = Invoke-Command -Computername localhost {netsh int tcp show global}
$result = @{}
$netshObject = New-Object psobject -Property @{
ReceiveSideScalingState = $Null
ChimneyOffloadState = $Null
NetDMAState = $Null
}
$netshResult = $netshResult | Select-String : #break into chunks if colon only
$i = 0
while($i -lt $netshResult.Length){
$line = $netshResult[$i]
$line = $line -split(":")
$line[0] = $line[0].trim()
$line[1] = $line[1].trim()
$result.$($line[0]) = $($line[1])
$i++
}
$netshObject.ReceiveSideScalingState = $result.'Receive-Side Scaling State'
$netshObject.ChimneyOffloadState = $result.'Chimney Offload State'
$netshObject.NetDMAState = $result.'NetDMA State'
这篇关于netsh 结果到 PowerShell 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文