container extract via ad cmdlet

is there a way via powershell cmdlets to extract users/computers within a container (including any subcontainers within the parent - if you can have such a thing in AD!). I am guessing CN represents container in the output of the 'applies to' attribute column in get-adfinegrainedpasswordpolicy
LVL 4
pma111Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hello ThereSystem AdministratorCommented:
Use this to get all users:
Get-ADUser -SearchBase “OU=childOU,OU=parentOU,DC=domainName,DC=local” -Filter * -ResultSetSize 5000 | Select Name,SamAccountName

Use this to get all computers:
Get-ADComputer -SearchBase “OU=childOU,OU=parentOU,DC=domainName,DC=local” -Filter *
0
oBdACommented:
Most of the objects in AD are containers. This will get all FGPPs and recursively expand the group membership of the respective groups:
Get-ADFineGrainedPasswordPolicy -Filter * | Sort-Object -Property Precedence | ForEach-Object {
	$FGPP = $_
	$_.AppliesTo | ForEach-Object {
		$ADObject = Get-ADObject -Identity $_ -Property SamAccountName
		If ($ADObject.ObjectClass -eq 'group') {
			Get-ADGroupMember -Identity $ADObject -Recursive
		} Else {
			$ADObject
		}
	} | Select-Object -Property @{n='FGPP_Name'; e={$FGPP.Name}}, @{n='FGPP_Precedence'; e={$FGPP.Precedence}}, SamAccountName, Name, DistinguishedName
} | Export-Csv -NoTypeInformation -Path C:\Temp\FGPPAppliesTo.csv

Open in new window

1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MichelangeloConsultantCommented:
The following code allows to specify a starting point for a search and produces a list of all users  following any tree down to the leaf.
Get-ADUser -filter { cn -like "*" } -searchbase "DC=childdomain1,DC=ad,DC=contoso,DC=com" -SearchScope Subtree 

Open in new window


In case you need to export a CSV, the following code will suffice.
In case you need to integrate it with FGPP code reporting I provided in your previous question, just let us know what you're trying to obtain
Get-ADUser -filter { cn -like "*" } -searchbase "DC=childdomain1,DC=ad,DC=contoso,DC=com" -SearchScope Subtree | select  Name, SamaccountName, objectclass, Distinguishedname | Export-Csv -Encoding UTF8 -Delimiter ";"

Open in new window


ciao
0
MichelangeloConsultantCommented:
Hello there solution does not get evaluated because it does not esplore subcontainers (it is missing searchscope parameter)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.