Skip to content

Commit 8d4059e

Browse files
committed
get-network -verbose
1 parent cf33375 commit 8d4059e

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

Modules/Scripts/Get-Network.ps1

+32-7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ machine. All other adpaters such as tunneling and loopbacks are ignored. Only
55
adapters are considered.
66
#>
77

8+
param([switch] $verbose)
9+
810
$preferred = $null
911

1012
$items = @()
@@ -18,8 +20,10 @@ if ([Net.NetworkInformation.NetworkInterface]::GetIsNetworkAvailable())
1820
Address = $null
1921
DNSServer = $null
2022
Gateway = $null
21-
Description = $null
22-
HasStats = $false
23+
Description = $null
24+
DnsSuffix = $null
25+
BytesReceived = 0
26+
BytesSent = 0
2327
Status = $_.OperationalStatus
2428
Type = $_.NetworkInterfaceType
2529
}
@@ -39,15 +43,21 @@ if ([Net.NetworkInformation.NetworkInterface]::GetIsNetworkAvailable())
3943
| select -first 1 -ExpandProperty Address
4044

4145
$stats = $_.GetIPv4Statistics() | Select -first 1
42-
$item.HasStats = ($stats.BytesReceived -gt 0) -and ($stats.BytesSent -gt 0)
46+
$item.BytesReceived = $stats.BytesReceived
47+
$item.BytesSent = $stats.BytesSent
4348

44-
$item.Description = $_.Name + ', ' + $_.Description
49+
$item.Description = $_.Name + ', ' + $_.Description
50+
$item.DnsSuffix = $props.DnsSuffix
4551
if (($props.DnsSuffix -ne $null) -and ($props.DnsSuffix.Length -gt 0))
4652
{
4753
if ($item.Type.ToString().StartsWith('Wireless'))
4854
{
49-
$profile = (netsh wlan show interfaces | Select-String '\sSSID').ToString().Split(':')[1].Trim()
50-
if ($profile) { $item.Description += (', ' + $profile) }
55+
$ssid = netsh wlan show interfaces | Select-String '\sSSID'
56+
if ($ssid)
57+
{
58+
$profile = $ssid.ToString().Split(':')[1].Trim()
59+
if ($profile) { $item.Description += (', ' + $profile) }
60+
}
5161
}
5262
else
5363
{
@@ -94,7 +104,22 @@ if ([Net.NetworkInformation.NetworkInterface]::GetIsNetworkAvailable())
94104
}
95105
else {
96106
Write-Host $line
97-
}
107+
}
108+
109+
if ($verbose)
110+
{
111+
if ($_.Status -eq 'Up')
112+
{
113+
Write-Host ("{0,47} Type{1} BytesSent:{2} BytesReceived:{3}" -f `
114+
'',$_.Type,$_.BytesSent, $_.BytesReceived) -ForegroundColor DarkGray
115+
116+
if ($_.DnsSuffix)
117+
{
118+
Write-Host ("{0,47} DnsSuffix:{1}" -f '',$_.DnsSuffix) -ForegroundColor DarkGray
119+
}
120+
}
121+
Write-Host
122+
}
98123
}
99124
}
100125
else

0 commit comments

Comments
 (0)