Join Linux to Active Directory with PowerShell Core
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: