Skip to content

Instantly share code, notes, and snippets.

@crypticgeek
Created August 21, 2017 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crypticgeek/2ab301f8c9a74d1320e48b260c6d8b06 to your computer and use it in GitHub Desktop.
Save crypticgeek/2ab301f8c9a74d1320e48b260c6d8b06 to your computer and use it in GitHub Desktop.
$map = Invoke-MapDomainTrust
$domains = (($map | select -ExpandProperty sourcename) + ($map | select -ExpandProperty targetname)) | Select-Object -Unique
ForEach ($computer in (gc computers.txt | Sort-Object -Unique)) {
ForEach ($domain in $domains) {
$fqdn = Get-DomainComputer -SearchBase "GC://$domain" -LDAPFilter "(name=$computer)" -Properties dnshostname
if ($fqdn -ne $null) {
$fqdn
break
}
}
if ($fqdn -eq $null) { Write-Error "Could not find $computer in $domains" }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment