diff --git a/MDT-JoinDomain.ps1 b/MDT-JoinDomain.ps1 index d6bee57..62e773a 100644 --- a/MDT-JoinDomain.ps1 +++ b/MDT-JoinDomain.ps1 @@ -10,6 +10,13 @@ Start-Transcript -Path "$MDTPath\_Logs\$CompName-JoinDomain.log" -Append $CompType = $args[0] $SubType = $args[1] +# Check if we're already in the domain +if ((gwmi win32_computersystem).partofdomain -eq $true) { + write-host -ForegroundColor Green "Already in the domain! Exiting." + Stop-Transcript + exit 0 +} + if ($CompType -like "WKS") { New-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\LSA" -Name NetJoinLegacyAccountReuse -Value 1 $PCNamePrefix = ($CompName.Substring(0,$CompName.IndexOf("-")))