ps/Modules/Alkami.PowerShell.Common/Public/Get-IpAddress.ps1

25 lines
588 B
PowerShell
Raw Normal View History

2023-05-30 22:51:22 -07:00
function Get-IpAddress {
<#
.SYNOPSIS
Returns the IP address of the server. Returns the private 10.* IP, or otherwise the first IPv4 address.
#>
[CmdletBinding()]
Param()
$ips = Get-NetIPAddress | Where-Object { ($_.AddressState -eq "preferred") -and ($_.AddressFamily -eq "IPv4") -and ($_.IPAddress -ne "127.0.0.1")};
$privateIP = $ips | Where-Object { $_.IPAddress -like "10.*"; } | Select-Object -First 1;
if($null -ne $privateIP)
{
return $privateIP.IPAddress;
}
$ip = $ips | Select-Object -First 1;
if($null -ne $ip)
{
return $ip.IPAddress;
}
return $null;
}