The following function uses the System.Net.NetworkInformation namespace to discover IPv4 address information. This allows us to return the same thing whether it is run on Windows or Linux.
If it were Windows only, we might have used WMI or the Get-NetIPConfiguration command. Creating something to work on both operating systems is more challenging:
function Get-IPConfig { [System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces() | ForEach-Object { $ipProperties = $_.GetIPProperties() $addresses = $ipProperties.UnicastAddresses | Where-Object { $_.Address.AddressFamily -eq 'InterNetwork' } | ForEach-Object { "$($_.Address) $($_.IPv4Mask)" } $gateway = $ipProperties.GatewayAddresses.Address | Where-Object { $_.AddressFamily -eq 'InterNetwork' -and $_ -ne '0.0.0.0' } [PSCustomObject]@{ Name = $_.Name Id = $_.Id Addresses = $addresses Gateway = $gateway } } | Where-Object { $_.Addresses } } Get-IPConfig