Powershell Quick script to show all Hosts file from all online machines in Active Directory Updated August 11 2024
Copy to Clipboard $OnlyThisComputer = "" # Use this to limit it to working on a single machine, say 'PC17', or make it blank to apply to all computers starting with 'PC'. $CheckHostsFile = $true $Computers = Get-ADComputer -Filter '*' | Select -ExpandProperty Name | Sort ForEach ($COMPUTER in $Computers){ if ( $true ){ if( ( $OnlyThisComputer.length -lt 1 -or $COMPUTER -eq $OnlyThisComputer ) ){ if (Test-Connection -Cn $computer -BufferSize 16 -Count 1 -ea 0 -quiet){ # Online Write-Host "$COMPUTER is on" if ( Test-Path "\\$($COMPUTER)\c$\Windows\System32\drivers\etc\hosts" ){ $HostsFileContent = Get-Content "\\$($COMPUTER)\c$\Windows\System32\drivers\etc\hosts" ForEach ($line in $($HostsFileContent -split "`r`n")){ $This = $line.trim() if ( $This.length -gt 0 -and $This.substring(0,1) -ne "#" ){ Write-host $This } } Write-Host "`r`n" } }else{ # Offline Write-Host "$COMPUTER is offline!" } } } }




©2024 - Some portions of this website are Copyrighted.
Your IP: 13.59.205.182     Referring URL:
Browser: Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Terms and Conditions, Privacy Policy, and Security Policy