Categories:
  🠪  General

Email
  🠪  Servers
  🠪  Testing
  🠪  Tips

Hardware
  🠪  3D Printing
  🠪  Apple
  🠪  Batteries
  🠪  Drives
  🠪  Edgerouter
  🠪  Electronics
  🠪  Laptop
  🠪  Modems
  🠪  Phone
  🠪  Printers
  🠪  Raspberry Pi
  🠪  Tablets
  🠪  Testing
  🠪  Virtualization

hidden
  🠪  General

Links
  🠪  Interesting
  🠪  Media

Network
  🠪  Data
  🠪  Testing
  🠪  VPN

Scripts
  🠪  Batch
  🠪  Linux
  🠪  Powershell

Servers
  🠪  Databases
  🠪  Misc
  🠪  Website

Software
  🠪  Other

Utilities
  🠪  Backup
  🠪  Fix Issues
  🠪  Recovery

Video
  🠪  Editing

Websites
  🠪  HTML
  🠪  Testing

Windows
  🠪  Adjustments
  🠪  Issues
  🠪  Remote Desktop
  🠪  Security
  🠪  Slow
  🠪  Software
  🠪  Startup

Submit Entry
Airin's Notes

Category: Scripts 🠪 Powershell
Quick script to show all Hosts file from all online machines in Active Directory
November 28, 2023

$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!"
}
}
}

}




This site is meant to be used as a reference for myself, although others may find it useful. I use it to keep track of certain fixes, software, and other solutions which I may need while assisting customers. The page layout is pure HTML/CSS and is kept simple to optimize loading time and fast results.

Return to Airin's Computers