netsh result to powershell object

后端 未结 3 859
长发绾君心
长发绾君心 2021-01-26 19:46

I am trying to work with netsh from powershell. I want see result from this command such as object, but netsh return string:

ne         


        
3条回答
  •  情深已故
    2021-01-26 20:17

    $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'
    

提交回复
热议问题