AD GPO SW Deploy - samuel-richardson/Sam-Tech-Journal GitHub Wiki

Creating OU via powershell

  • Creating an OU under samuel.local

New-ADOrganizationalUnit -Name "OU Name" -path "DC=samuel,DC=local"

Deleting OU via powershell

  • Deleting an OU under samuel.local with accidental deletion protection.

Remove-ADOrganizationalUnit -Identify "OU=OU Name,DC=samuel,DC=local"

  • If this does not work login to AD as Adminstrator and run the following.

GET-ADOrganizationalUnit -Identify "OU=OU Name,DC=samuel,DC=local" | Set-ADObject -ProtectedFromAccidentalDeletion:$false -PassThru | Remove-ADOrganizationalUnit

Moving items to a new OU in powershell

  • Moving objects into the OU we created.
  • Moving a computer object.

Get-ADComputer "computerName" | Move-ADObject -TargetPath "OU=OU Name,DC=samuel,DC=local"

  • Moving a user object.

Get-ADUser "userName" | Move-ADObject -TargetPath "OU=OU Name,DC=samuel,DC=local"

Search Event log with powershell

  • Get an event by searching with the event id and source.

Get-EventLog -LogName System -Source "Appplication Management Group Policy" | Where-Object {$_.EventID -eq 302}