This powershell function helps you to get the network status of all network adapters in a given computer. Using this script it is easy to determine the status of all network connections in remote computer to see whether it is connected/disconnected/media disconnected/and different other statuses. This script queries Win32_NetworkAdapter WMI class for list of network adapters and then fetches the status of each adapter by querying “netconnectionstatus” parameter. This is a uint16 data type which returns any value ranging from 0-12. Each value from 0 to 12 has it’s own meaning. See the below table for details(source: MSDN)
Value | Meaning |
---|---|
|
Disconnected |
|
Connecting |
|
Connected |
|
Disconnecting |
|
Hardware not present |
|
Hardware disabled |
|
Hardware malfunction |
|
Media disconnected |
|
Authenticating |
|
Authentication succeeded |
|
Authentication failed |
|
Invalid address |
|
Credentials required |
So, here is the script which lists the network adapter name and its status.
Script:
function Get-NetworkConnectionStatus { param( $ComputerName=$env:computername ) $statushash = @{ 0 = "Disconnected" 1 = "Connecting" 2 = "Connected" 3 = "Disconnecting" 4 = "Hardware not present" 5 = "Hardware disabled" 6 = "Hardware malfunction" 7 = "Media Disconnected" 8 = "Authenticating" 9 = "Authentication Succeeded" 10 = "Authentication Failed" 11 = "Invalid Address" 12 = "Credentials Required" } $networks = Gwmi -Class Win32_NetworkAdapter -ComputerName $computername $networkName = @{name="NetworkName";Expression={$_.Name}} $networkStatus = @{name="Networkstatus";Expression=` {$statushash[[int32]$($_.NetConnectionStatus)]}} foreach ($network in $networks) { $network | select $networkName, $Networkstatus } }
Usage:
Get-NetworkConnectionStatus -ComputerName PC1
Hope this helps…
Comments on this entry are closed.
Hi,
This is a good post .Just want to drill further ,
Lets say i have group of computers and all have connection named “local Area Connection” now i want to ,
1.Display a page that shows all computers and their conenction name “local Area Conenction” highlighted in green
2.If any connection name has been changed or missing it displays as red.
– Regards
Sunny