AD GPO - eamonstackpole/my-tech-journal GitHub Wiki
Overview
Creating & Removing OUs
Creating OU
- New-ADOrganizationalUnit -Name "Software Deploy" -Path "DC=eamon,DC=local"
-
- -ProtectedFromAccidentalDeletion $False to disable accidental deletion prevention
Removing OU
-
Remove-ADOrganizationalUnit -Identity "OU=Test OU,DC=eamon,DC=local"
-
If it is accidental deletion protected, you must run the following command first:
-
- Get-ADOrganizationalUnit -identity "OU=Test OU,DC=eamon,DC=local" | Set-ADObject -ProtectedFromAccidentalDeletion:$false
Moving an Object to an OU
Moving a User
- Move-ADObject -Identity "d5f93e63-8da0-4c41-b53a-a69b48bb4d85" -TargetPath "OU=Software Deploy,DC=eamon,DC=local"
Moving a Computer
- Move-ADObject -Identity "7b9d3462-de65-42fb-89e9-1408d9475f4f" -TargetPath "OU=Software Deploy,DC=eamon,DC=local"
Checking Event Logs
Finding an Event Log in Powershell using the EventID
- Get-EventLog -LogName (category) -InstanceId (code number)
-
- Use Select-Object -Property (Property) to print specific details/properties about the log
Notes
- Get-ADOrganizationalUnit -Filter 'Name -like "*"' | Format-Table Name, DistinguishedName -A
-
- Lists all OUs on the domain
- Use notepad.exe command to launch notepad to write a .ps1 script
Issues
- Powershell didn't recognize Distinguished names
-
- Solved by using GUIDs
Sources
- https://learn.microsoft.com/en-us/powershell/module/activedirectory/remove-adorganizationalunit?view=windowsserver2022-ps
- https://learn.microsoft.com/en-us/powershell/module/activedirectory/get-adorganizationalunit?view=windowsserver2022-ps
- https://learn.microsoft.com/en-us/powershell/module/activedirectory/new-adorganizationalunit?view=windowsserver2022-ps
- https://learn.microsoft.com/en-us/powershell/module/activedirectory/move-adobject?view=windowsserver2022-ps