# Testing MDT bullshit # Technolog Networks # iRaven $CompName = $env:COMPUTERNAME Start-Transcript -Path "c:\$CompName-TESTScript.log" -Append # General necessities. $TSEnv = New-Object -ComObject Microsoft.SMS.TSEnvironment $CompType = $args[0] $SubType = $args[1] Write-Host "Username: $env:username" Write-Host "MDT DeployRoot: $Global:TSEnv.Value("DeployRoot")" $MDTun = [System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String($Global:TSEnv.Value("SMSConnectNetworkFolderAccount"))) Write-Host "MDT UserName: $MDTun" Read-Host -Prompt "Balls..." if ($CompType -like "WKS") { $PCNamePrefix = ($CompName.Substring(0,$CompName.IndexOf("-"))) # Domain credentials to join WKS to domain $MDTPath = $Global:TSEnv.Value("DeployRoot") . "$MDTPath\_Scripts\Credentials-MDTJoinDomain.ps1" Write-Host "Auto-detecting computer name $CompName..." # Filter out OUs if ($PCNamePrefix -like "XH") { Write-Host "Detected computer name as XH - domain joining to Personal WKS OU" $DomainOU = "OU=Personal,OU=Workstations,DC=technolog,DC=net" } elseif ($PCNamePrefix -like "TNG" -or $PCNamePrefix -like "NH" -or $PCNamePrefix -like "IR") { Write-Host "Detected computer name as TNG, NH, or IR - domain joining to Standard WKS OU" $DomainOU = "OU=Workstations,DC=technolog,DC=net" } elseif ($PCNamePrefix -like "TEST") { Write-Host "Detected computer name as TEST - domain joining to Testing WKS OU" $DomainOU = "OU=TestingWKS,OU=Workstations,DC=technolog,DC=net" } else { Write-Host "Computer name is unusual - domain joining to Standard WKS OU" $DomainOU = "OU=Workstations,DC=technolog,DC=net" } } elseif ($CompType -like "Server") { $DomainCredential = Get-Credential -Message "To join this server to the domain, enter your domain credentials." # 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" } } elseif ($CompType -like "Utility") { . "z:\_Scripts\Credentials-MDTJoinDomain.ps1" Write-Host "Domain joining to Utility OU" $DomainOU = "OU=Utility,DC=technolog,DC=net" } else { . "z:\_Scripts\Credentials-MDTJoinDomain.ps1" Write-Host "Domain joining to generic Computers OU" } 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