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 3
pma111Asked:
Who is Participating?
 
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
 
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
 
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
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.