scripts/Standalone-JoinDomain.ps1
2025-04-09 23:17:45 -05:00

54 lines
1.6 KiB
PowerShell

# Script to join domain inside of MDT.
# Technolog Networks, 2024-08-21
# iRaven
Start-Transcript -Path "c:\irnh\Standalone-JoinDomain.log" -Append
# General necessities.
$CompName = $env:COMPUTERNAME
# Domain Credentials to be used
. "\\berrypunch.technolog.net\PSCredentials$\Credentials-WKSDeploy.ps1"
$CompType = $args[0]
$SubType = $args[1]
if ($CompType -like "WKS") {
$PCNamePrefix = ($CompName.Substring(0,$CompName.IndexOf("-")))
# Filter out OUs
if ($PCNamePrefix -like "XH") {
$DomainOU = "OU=Personal,OU=Workstations,DC=technolog,DC=net"
}
elseif ($PCNamePrefix -like "TNG" -or $PCNamePrefix -like "NH" -or $PCNamePrefix -like "IR") {
$DomainOU = "OU=Workstations,DC=technolog,DC=net"
}
elseif ($PCNamePrefix -like "TEST") {
$DomainOU = "OU=TestingWKS,OU=Workstations,DC=technolog,DC=net"
}
} elseif ($CompType -like "Server") {
$DomainCredential = Get-Credential
# Filter out SubType var for server tiers
if ($SubType -ne $null) {
$DomainOU = "OU=$SubType,OU=Domain Servers,DC=technolog,DC=net"
} else {
$DomainOU = "OU=Domain Servers,DC=technolog,DC=net"
}
}
if ([boolean](get-variable "DomainOU" -ErrorAction SilentlyContinue)) {
try {
Add-Computer -DomainName technolog.net -Credential $DomainCredential -OUPath $DomainOU -Restart
} catch {
Write-Host "Couldn't join the domain with OU $DomainOU"
}
}
else {
try {
Add-Computer -DomainName technolog.net -Credential $DomainCredential -Restart
} catch {
Write-Host "Couldn't join the domain!"
}
}
Stop-Transcript