get-adcomputer to list objects in a specific OU

Dear All,

I have the followiing structure in my AD, see attached file.
I need to use get-adcomputer -searchbase .... to list all computers in the OU computers only. I dont want to have Servers.
How I can achieve that?

Thks
Capture.JPG
celmajjAsked:
Who is Participating?
 
MaheshArchitectCommented:
Get-ADComputer -Filter {OperatingSystem -NotLike "*server*"} -Property * -Searchbase "ou=test,dc=domain,dc=,com"| Select Name,OperatingSystem,OperatingSystemServicePack | Export-csv C:\computer.csv -NoTypeInformation
1
 
Naveen SharmaCommented:
You can try the below script to get a list of all computers from a certain OU

Get-ADComputer -Filter * -SearchBase "OU=TestOU,DC=TestDomain,DC=com" -Properties *  |
 Select -Property Name,DNSHostName,LastLogonDate

For more information, please refer to the article.

http://www.morgantechspace.com/2016/03/get-all-computers-from-ou-in-ad-using-powershell.html

Hope it helps
0
 
oBdACommented:
By pulling the OUs named "Computers" first, and then pulling all computers in there.
Get-ADOrganizationalUnit -Filter {Name -eq 'Computers'} |
	ForEach-Object {Get-ADComputer -Filter * -SearchBase $_.DistinguishedName} |
	Select-Object -Property Name, Enabled, DistinguishedName |
	Sort-Object DistinguishedName |
	Export-Csv -NoTypeInformation -Path C:\Temp\ADComputers.csv

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.