Description
The script connects to a domain controller and retrieves a list of GPOs. It then extracts relevant properties, such as the display name, creation date, modification date, and distinguished name. Finally, it formats this data into PowerShell objects and outputs the results in a structured format.
Overviewa
This PowerShell script automates the process of retrieving and displaying information about Group Policy Objects (GPOs) from an Active Directory domain. It starts by connecting to the domain controller, authenticating using the provided administrator credentials or impersonation. Using the Get-GPO cmdlet, it queries all available GPOs and extracts four key attributes:
- Display Name: The human-readable name of the GPO.
- Creation Date: The timestamp indicating when the GPO was created.
- Modification Date: The timestamp showing when the GPO was last modified.
- Distinguished Name: The LDAP path representing the GPO’s unique identity in Active Directory.
For each retrieved GPO, the script constructs a new PowerShell object with these properties and outputs a formatted list, making it easy to review the details of each GPO.
Parameters
| Name | Type | Description |
|---|---|---|
| Domain | string | The domain to connect to. |
| DomainController | string | The IP address or hostname of the target Domain Controller. |
| Username | string | The domain username to authenticate with. |
| Password | string | The password for the specified user. |
Example Output
Name Created Modified DistinguishedName
---- ------- -------- -----------------
Default Domain Policy 6/13/2022 6:56:46 PM 8/22/2024 3:20:17 PM CN={31B2F340-016D-11D2-945F-00C04FB984F9},CN=Policies,CN=System,DC=lab,DC=net
Default Domain Controllers Policy 6/13/2022 6:56:46 PM 4/9/2025 11:14:06 AM CN={6AC1786C-016F-11D2-945F-00C04fB984F9},CN=Policies,CN=System,DC=lab,DC=net
Example Json Output
[
{
"Name": "Default Domain Policy",
"Created": "2022-06-13T18:56:46",
"Modified": "2024-08-22T15:20:17",
"DistinguishedName": "CN={31B2F340-016D-11D2-945F-00C04FB984F9},CN=Policies,CN=System,DC=lab,DC=net",
},
{
"Name": "Default Domain Controllers Policy",
"Created": "2022-06-13T18:56:46",
"Modified": "2024-08-22T15:19:48",
"DistinguishedName": "CN={6AC1786C-016F-11D2-945F-00C04fB984F9},CN=Policies,CN=System,DC=lab,DC=net"
}
]
