powershellactive-directorypowershell-3.0

How to remove property header from output when runnign Get-ADComputer


I want to pull the names of computer objects in AD in to a file. The method I'm trying so far is this

$computers = Get-ADComputer -Filter * | Format-List name
write($computers) | Out-File -FilePath .\computers.txt

The issue I have with this though is that the file that is output looks like this:

name : SERVER1

name : SERVER2

name : WORKSTATION1

name : WORKSTATION2

And I'm looking for just a straight list of names with out the "name : " part that comes in front.


Solution

  • $computers = Get-ADComputer -Filter * | select-object -expandproperty name | out-file .\computers.txt
    

    This should be faster than MDMoore313's solution by virtue of not looping through the results & writing to disk on each trip through (1.7s for his vs. 1.1s for mine in my AD environment, writing to a RAMDisk).