We help IT Professionals succeed at work.

Export Computer names from Active Directory to Text File

Hello

I need to be able to export a list of all my laptops, desktops and servers from a perticular OU on Active Directory into a text file.

It also has to be in a perticular format:

<computername>; <computername>; <computername>;

Any ideas?

Thanks

Andrew
Comment
Watch Question

Senior Active Directory Engineer
Top Expert 2012
Commented:
Have you considered using Windows PowerShell for that?

Run in PS on 2008 this command

Get-ADComputer -name * -SearchBase "ou=OULocation,dc=domain,dc=local" -SizeLimit 0 -Properties * | Select name | Export-CSV c:\computers.csv

Regards,
Krzysztof

Author

Commented:
Hi

THanks for the info but could you please explain a little more how i do that?  I've never used PowerShell before

Thanks
Krzysztof PytkoSenior Active Directory Engineer
Top Expert 2012

Commented:
On Windows Server 2008 from Administrative Tools run Active Directory PowerShell module and paste there this syntax.

It queries specified OU in distinguished name format for each computer object and gets all computer properties. After that (|) output is sent over pipe to another command which selects computer name from all properties and then sends it over Export-CSV cmdlet to CSV file on C-Drive

Krzysztof

Author

Commented:
Thanks

Will this give me the appropriate format as well?  I need it to be in a text file with the format as above
Krzysztof PytkoSenior Active Directory Engineer
Top Expert 2012

Commented:
It will be in text file (open it with notepad) and remove unnecessary lines. As separator you should see (;) or (,)

Krzysztof
steforIT Security Architect

Commented:
To get that format of the output in a text file. Still in powershell as above stated.

Get-ADComputer -name * -SearchBase "ou=OULocation,dc=domain,dc=local" -SizeLimit 0 -Properties * | foreach {$_.Name + ";" + $_.Name + ";" + $_.Name + ";"} | Out-File "C:\TEMP\computerlist.txt"

Open in new window

Author

Commented:
Thanks

Is there a way to filter it as well so that any computer name that contains "tb" is excluded from the list?  I don't want Tablet computers to be exported

Author

Commented:
Sorry to be a pain but which parts of the above to enter into powershell do i actually need to change?

Author

Commented:
IF i run it i get the attached error
ScreenHunter-01-Dec.-06-13.02.jpg
steforIT Security Architect
Commented:
Get-ADComputer -SearchBase "ou=OULocation,dc=domain,dc=local" -SizeLimit 0 -Properties * | foreach {$_.Name + ";" + $_.Name + ";" + $_.Name + ";"} | Out-File "C:\TEMP\computerlist.txt"

Open in new window

Try this without the "-name *" then.

In order to exclude tb you could do this:
Get-ADComputer -Filter{Name -notlike "*tb*"} -SearchBase "ou=OULocation,dc=domain,dc=local" -SizeLimit 0 -Properties * | foreach {$_.Name + ";" + $_.Name + ";" + $_.Name + ";"} | Out-File "C:\TEMP\computerlist.txt"

Open in new window

Author

Commented:
Thanks for the help, managed to get it working in the end