Skip to content

Instantly share code, notes, and snippets.

@daurrutia
Created February 6, 2018 21:12
Show Gist options
  • Save daurrutia/d48a6870731e37e3f21227271484d4c9 to your computer and use it in GitHub Desktop.
Save daurrutia/d48a6870731e37e3f21227271484d4c9 to your computer and use it in GitHub Desktop.
Get and write out list of Windows Server computer names in a domain.
## Get list of all AD Computer Objects
#Get-ADComputer -filter * -Properties dnshostname,operatingsystem | sort Name | select Name,DNSHostName,OperatingSystem
## Export list of all AD Computer Objects inlcuding Ipv4Address property
#Get-ADComputer -filter * -Properties dnshostname,operatingsystem,ipv4address | sort Name | select Name,DNSHostName,Ipv4Address,OperatingSystem | out-file C:\Users\david.urrutia\Desktop\computerIpList.txt
## Get list of all Windows Server computers
#Get-ADComputer -filter {operatingsystem -like "*server*"} -Properties dnshostname,operatingsystem | sort Name | select Name,DNSHostName,OperatingSystem
## Get list of all Windows Server computers
#Get-ADComputer -filter {operatingsystem -like "*server*"} -Properties dnshostname | sort Name | select -ExpandProperty DNSHostName
## Get list of all enabled Windows "Server" computer object DNS hostnames and write list to current working directory
$path=Get-Location
Get-ADComputer -filter {(operatingsystem -like "*server*") -and (enabled -eq "true")} -Properties dnshostname | sort Name | select -ExpandProperty DNSHostName | Out-File $path\ComputerList.txt
Write-Host "List written to $path\ComputerList.txt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment