From 4b32744424ee3c0307ee9a24ad9bba330e9ad5ed Mon Sep 17 00:00:00 2001 From: Jeff Kwan Date: Thu, 3 Sep 2015 16:54:41 -0400 Subject: [PATCH] Use a .NET API call instead of a Win8+ cmdlet The root cause is that Windows 7 doesn't have Get-NetIPAddress ( see: https://stackoverflow.com/questions/19529442/gather-ip-address-information ) but the change was to try and solve the bug that the VPN IP addresses aren't visible detailed here: https://support.microsoft.com/en-us/kb/2549091 Resolved using the 2nd solution from http://serverfault.com/questions/145259/powershell-win32-networkadapterconfiguration-not-seeing-ppp-adapter --- .../synced_folders/smb/scripts/host_info.ps1 | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/plugins/synced_folders/smb/scripts/host_info.ps1 b/plugins/synced_folders/smb/scripts/host_info.ps1 index 0e089932e..c4f13aada 100644 --- a/plugins/synced_folders/smb/scripts/host_info.ps1 +++ b/plugins/synced_folders/smb/scripts/host_info.ps1 @@ -1,11 +1,21 @@ -$ErrorAction = "Stop" - -$net = Get-NetIPAddress | Where-Object { - ($_.IPAddress -ne "127.0.0.1") -and ($_.IPAddress -ne "::1") -} | Sort-Object $_.AddressFamily - -$result = @{ - ip_addresses = $net.IPAddress -} - -Write-Output $(ConvertTo-Json $result) +$ErrorAction = "Stop" + +# Find all of the NICsq +$nics = [System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces() + +# Save the IP addresses somewhere +$nic_ip_addresses = @() + +foreach ($nic in $nics) { + $nic_ip_addresses += $nic.GetIPProperties().UnicastAddresses | Where-Object { + ($_.Address.IPAddressToString -ne "127.0.0.1") -and ($_.Address.IPAddressToString -ne "::1") + } | Select -ExpandProperty Address +} + +$nic_ip_addresses = $nic_ip_addresses | Sort-Object $_.AddressFamily + +$result = @{ + ip_addresses = $nic_ip_addresses.IPAddressToString +} + +Write-Output $(ConvertTo-Json $result)