Last active
June 11, 2025 05:59
-
-
Save SanjaySRocks/bb487fe69b09282f74486e3faba6c20a to your computer and use it in GitHub Desktop.
GetDeviceInfo PowerShell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Get Device Name and Model | |
| $computerSystem = Get-WmiObject -Class Win32_ComputerSystem | |
| $computerName = $computerSystem.Name | |
| $manufacturer = $computerSystem.Manufacturer | |
| $model = $computerSystem.Model | |
| $deviceName = "$manufacturer $model" | |
| # Get Device Serial Number | |
| $bios = Get-WmiObject -Class Win32_BIOS | |
| $serialNumber = $bios.SerialNumber | |
| Write-Output "----------------------------------------" | |
| Write-Output "Device Name : $deviceName" | |
| Write-Output "Device Serial Number: $serialNumber" | |
| Write-Output "----------------------------------------" | |
| Write-Output "Network Adapter Details:" | |
| Write-Output "" | |
| # Get All Network Adapters Info (Like getmac /v) | |
| Get-NetAdapter | Select-Object ` | |
| InterfaceAlias, ` | |
| InterfaceDescription, ` | |
| MacAddress, ` | |
| Status | Format-Table -AutoSize | |
| Write-Output "" | |
| Write-Output "IP Configuration Information:" | |
| Write-Output "" | |
| # IPConfig Info in Table | |
| Get-NetIPConfiguration | Select-Object ` | |
| InterfaceAlias, ` | |
| @{Name='IPv4Address';Expression={($_.IPv4Address.IPAddress -join ', ')}}, ` | |
| @{Name='IPv6Address';Expression={($_.IPv6Address.IPAddress -join ', ')}}, ` | |
| @{Name='DefaultGateway';Expression={($_.IPv4DefaultGateway.NextHop -join ', ')}}, ` | |
| @{Name='DNSServers';Expression={($_.DNSServer.ServerAddresses -join ', ')}} | Format-Table -AutoSize | |
| Write-Output "" | |
| Write-Output "Active Internet Connection (Default Route):" | |
| Write-Output "" | |
| # Detect Active Internet Adapter (Default Route) | |
| $internetRoute = Get-NetRoute -DestinationPrefix '0.0.0.0/0' | Where-Object { $_.NextHop -ne '0.0.0.0' } | Sort-Object RouteMetric | Select-Object -First 1 | |
| if ($internetRoute) { | |
| $adapter = Get-NetAdapter -InterfaceIndex $internetRoute.InterfaceIndex | |
| $ipconfig = Get-NetIPConfiguration -InterfaceIndex $internetRoute.InterfaceIndex | |
| [PSCustomObject]@{ | |
| InterfaceAlias = $adapter.InterfaceAlias | |
| Status = $adapter.Status | |
| IPv4Address = ($ipconfig.IPv4Address.IPAddress -join ', ') | |
| DefaultGateway = ($ipconfig.IPv4DefaultGateway.NextHop -join ', ') | |
| } | Format-Table -AutoSize | |
| } | |
| else { | |
| Write-Output "No active internet connection detected." | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment