Created
December 19, 2022 17:57
-
-
Save toksikk/1cd89f7b37107d8b2962356b488f201b to your computer and use it in GitHub Desktop.
small powershell script to check a local lancache resolver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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