Please assist. I'm getting familiar with PowerShell but I'm struggling with this new script. I have a list of FQDN Hostnames. They can be in either 3 different domains (1 forest) or not present at all (e.g. in another forest).
I want a PowerShell script that outputs another txt file with hostname,found in <domain>
This is how far I have come but it's not doing much. Also, I'm not sure how the $_ works here as I found this piece of code as a solution for a similar use case.
Behind the # I placed some code I tried as well.
$dcs = @("xx.****.com","xx.***.com","xx.***.com") | % {
foreach ($hostname in (Get-Content C:\Scripts\hostnames.txt)){
$check = Get-ADComputer $hostname -Server $_ #$hostname #-Filter { DNSHostname -eq $hostname $_}
if($check){
write-host "$hostname found in $_"
}
else{
write-host "$hostname not found in any domain"
}}}