• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 50
  • Last Modified:

Powershell: get data of netsh in hashtable


$Info = netsh mbn show interface gives below output.

How can I get this in a hashtable so I can select $Info.Name, $Info.Description etc?
I could use  $Name = $Info | Select-String  name but that gives two results. Could use $Info[6] then split select etc
... But there has to be an easier way right?


There is 1 interface on the system:

    Name               : Mobile Broadband Connection
    Description        : Wireless Mobile Broadband Network Adapter
    GUID               : {FF2782E0-33E0-4F84-92A4-EEFF24EEFFC89}
    Physical Address   : 01:a0:c8:00:06:14
    State              : Not connected
    Device type        : Mobile Broadband device is embedded in the system
    Cellular class     : GSM
    Device Id          : 3535112347061191
    Manufacturer       : Wireless, Incorporated
    Model              : SC7215
    Firmware Version   : SWI9X15C_01.12.00.01 9903149 01
    Provider Name      :
    Roaming            : Not roaming
    Signal             : 0%

Pleas advise.
1 Solution
At the end of the script, $result will contain an object with the respective properties:
$properties = 'Name', 'Description', 'GUID', 'Physical Address', 'State', 'Device type', 'Cellular class', 'Device Id', 'Manufacturer', 'Model', 'Firmware Version', 'Provider Name', 'Roaming', 'Signal'
$result = '' | Select-Object -Property $properties
& netsh.exe mbn show interface | ForEach-Object {
	$key, $value = $_.Split(':', 2) | ForEach-Object {$_.Trim()}
	If ($properties -contains $key) {
		$result.$key = $value

Open in new window

Jose Gabriel Ortega CEE Solution Guide - CEO Faru Bonon ITCommented:
What about using regex:

$info= netsh.exe mbn show interface
$pattern="\: (.*)"

foreach($match in [System.Text.RegularExpressions.Regex]::Matches($info,$pattern)){
    switch ($i)
        1 {$name =$match.Groups[1].Value}
        2 {$Description=$match.Groups[1].Value}
        3 {$GUID =$match.Groups[1].Value}
        4 {$PA =$match.Groups[1].Value}
        5 {$state =$match.Groups[1].Value}
        6 {$dt =$match.Groups[1].Value}
        7 {$cc =$match.Groups[1].Value}
        8 {$did =$match.Groups[1].Value}
        9 {$manufacturer =$match.Groups[1].Value}
        10 {$Model =$match.Groups[1].Value}
        11 {$Firmware =$match.Groups[1].Value}
        12 {$Provider =$match.Groups[1].Value}
        13 {$Roaming =$match.Groups[1].Value}
        14 {$signal =$match.Groups[1].Value}
$final = new-object psobject -Property @{
"name"=$name; "Description" = $Description; "GUID" = $GUID; "Physical Adddress"=$PA; "state"=$state; 
"Device Type"= $dt; "Celular class"=$cc; "Device Id"= $did; "manufacturer" =$manufacturer; 
"Model"=$Model; "Firmware Version"=$Firmware; "Provider Name"=$Provider; "Roaming" =$Roaming;
"Signal" = $signal;}


Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now