Skip to content

Instantly share code, notes, and snippets.

@toksikk
Created December 19, 2022 17:57
Show Gist options
  • Save toksikk/1cd89f7b37107d8b2962356b488f201b to your computer and use it in GitHub Desktop.
Save toksikk/1cd89f7b37107d8b2962356b488f201b to your computer and use it in GitHub Desktop.
small powershell script to check a local lancache resolver
# Define the script parameters
param (
[string]$FilePath = "C:\path\to\hostname\list.txt",
[string]$IPAddress = "10.13.37.160"
)
# Read the list of hostnames from the file
$hostnames = Get-Content -Path $FilePath
# Iterate over each hostname in the list
foreach ($hostname in $hostnames) {
# Try to resolve the hostname to an IP address
try {
$ip = [System.Net.Dns]::GetHostAddresses($hostname)
}
catch {
# Print an yellow warning message if an exception is caught
Write-Host "$hostname could not be resolved: $($_.Exception.Message)" -ForegroundColor Yellow
continue
}
# Check if the resolved IP address is the one specified in the parameter
if ($ip -eq $IPAddress) {
# Print a green message if the IP address matches
Write-Host "$hostname resolved to $IPAddress" -ForegroundColor Green
}
else {
# Print a red message if the IP address does not match
Write-Host "$hostname did not resolve to $IPAddress" -ForegroundColor Red
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment