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
...
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?
You got a few alternatives, none of which are nice.
1) Read the
netsh
output into astring[]
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 isMode
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.