netsh result to powershell object

后端 未结 3 864
长发绾君心
长发绾君心 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:06

    You got a few alternatives, none of which are nice.

    1) Read the netsh output into a string[] and use a custom record parser to create your own object. That is, look at the output on different locales and find out if, say, Hosted newtork settings is always the first header followed by bunch of - characters. If that's the case, assume that next element in array is Mode and so on. This is very error prone, but usually MS command line tools only translate messages, not their order.

    2) Look for .Net API for the same information. There is System.Net.NetworkInformation which contains a bunch of connection things. It's a start, though I am not sure if it has info you need.

    3) Failing the previous options, use P/Invoke to call native Win32 API. It's a lot of work, so look for pre-existing wrapper libraries before rolling your own.

提交回复
热议问题