Advertisement
opexxx

Listing all GPOs in the current forest

May 3rd, 2014
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. Let’s say I have a forest and I’d like to document a listing of all the GPOs in that forest. And maybe be able to list the GPOs mapped to the domain the GPO is created in.
  2.  
  3. I can start with the Get-ADForest cmdlet which creates an object for the forest I’m logged into. This object has a Domains property. How do I know this? I can find this out by running:
  4.  
  5. Get-ADForest | Get-Member
  6. Once I know that I can get a list of all the domains in the forest using the Domains property, I can pipe those domain names into the Get-GPO cmdlet to find the names of all GPOs for each domain in the forest.
  7.  
  8. Here’s how it works out in one long line:
  9.  
  10. (get-ADForest).domains | foreach { get-GPO -all -Domain $_ | Select-Object @{n='Domain Name';e={$_.DomainName}}, @{n='GPO Name';e={$_.DisplayName}} }
  11. The Select-Object cmdlet is used to create an associative array:
  12. http://en.wikipedia.org/wiki/Associative_array
  13. that maps the domain name with the GPO name.
  14.  
  15. For a sample domain called corp.Contoso.com, with a child domain of HQ.corp.Contoso.com, with one test GPO named testGPO, I would get a listing that looks like this:
  16.  
  17. Domain Name GPO Name
  18.  
  19. ----------- --------
  20.  
  21. corp.contoso.com Default Domain Policy
  22.  
  23. corp.contoso.com testGPO
  24.  
  25. corp.contoso.com Default Domain Controllers Policy
  26.  
  27. HQ.corp.contoso.com Default Domain Policy
  28.  
  29. HQ.corp.contoso.com Default Domain Controllers Policy
  30. Pipe the output of this command to the Out-Gridview cmdlet to get a spreadsheet style listing of GPOs for each domain in the forest.
  31.  
  32. (get-ADForest).domains | foreach { get-GPO -all -Domain $_ | Select-Object @{n='Domain Name';e={$_.DomainName}}, @{n='GPO Name';e={$_.DisplayName}} } | Out-Gridview
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement