Join Linux to Active Directory with PowerShell Core

PowerShell Core is now generally available, which means you can now start running it on your production servers and not feel guilty! There are many possibilities for using PowerShell on non-Windows platforms now and today my mind was pondering how to use it to join Linux servers to Active Directory. So, I created a small little function that automates some of this called Join-LinuxToAD. Keep in mind I tested this only on CentOS 7.

The script does the following:

  • Ensures you can lookup the domain with nslookup
  • Ensures Samba and other dependencies are installed via yum
  • Uses the realm command to join the local server to an Active Directory domain

While this is not totally automated, it does at least some of the work for you. I use $LASTEXITCODE has a way to do some error checking in the script.

Now lets run it:

Fun times!

Leave a Reply

Your email address will not be published. Required fields are marked *