36 lines
929 B
PowerShell
36 lines
929 B
PowerShell
function Compare-StringToLocalMachineIdentifiers {
|
|
<#
|
|
.SYNOPSIS
|
|
Compares a given string to see if it matches local machine identifiers (hostname, ip address)
|
|
#>
|
|
[CmdletBinding()]
|
|
[OutputType([System.Boolean])]
|
|
param (
|
|
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
|
|
[string]$stringToCheck
|
|
)
|
|
|
|
$trimmedString = $stringToCheck.Trim()
|
|
|
|
if (Test-IsStringIPAddress $trimmedString) {
|
|
$localIPV4Addresses = Get-NetIPAddress | Where-Object {$_.AddressFamily -eq "IPv4"} | Select-Object -ExpandProperty IPAddress
|
|
|
|
if ($localIPV4Addresses -contains $trimmedString) {
|
|
return $true
|
|
}
|
|
|
|
return $false
|
|
}
|
|
|
|
$localHostMatches = @(
|
|
"localhost",
|
|
$env:COMPUTERNAME.ToLowerInvariant(),
|
|
(Get-FullyQualifiedServerName)
|
|
)
|
|
|
|
if ($localHostMatches -icontains $trimmedString) {
|
|
return $true
|
|
}
|
|
|
|
return $false
|
|
} |