Active Directory and PowerShell


We all have added many computers to a Domain, moved them between OU’s, renamed them too. Using the Windows GUI is a tedious process with many steps. The nice thing about PowerShell is that it’s quick, easy and can be scripted to do multiple computers at one time. Even in the one computer at a time scenario it saves a few minutes a computer.

So, how do we do it? Add-Computer, Move-ADObject, Rename-Computer, Restart-Computer are all great cmdlets that make the job seamless and fast. The following command adds the local computer naming it Win10-TL to the domain called “YourDomain” and then restarts the computer to process the change in AD and on the computer immediately.

Add-Computer -ComputerName “Win10-TL” -DomainName “YourDomain” -Restart

That is way too easy for me. I need a harder way to do it so my boss thinks I’m a genius when I get things done fast and efficiently. Now, I’m all for looking like Scotty from Star Trek, but I also value my time and will look for anything that will make my job easier so that I can work on other interesting  projects.

Want to move that computer from the default Computer OU to the new OU it belongs in?

get-adcomputer Win10-TL | Move-ADObject -TargetPath ‘ou=staff computers,dc=mydomain,dc=net’

You can shorten the move command above by using other methods. One I like is placing the TargetPath into a Variable called $TP.

Work smarter, not harder.

Advertisements