Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $domain = "our.domain.com"
- $DomainJoin = 1
- $CreateAccount = 2
- $AllowJoinIfAlreadyJoined = 32
- $user = $credentials.username
- $pass = ($credentials.getnetworkcredential()).password
- $computer = get-wmiobject Win32_ComputerSystem
- $ret = $computer.rename($computername,$credentials.getnetworkcredential()).password,$credentials.username)
- if ($ret.ReturnValue -eq 0)
- {
- $ret = $computer.JoinDomainOrWorkGroup($domain,($credentials.GetNetworkCredential()).Password, $credentials.UserName, $OU, 0x1 + 0x2 + 0x20 + 0x400)
- Switch ($ret.ReturnValue)
- {
- "2224" {
- $ret = $computer.JoinDomainOrWorkGroup($domain,$pass,$user,$OU,33)
- if ($ret.ReturnValue -eq 1332) { write-host "Computer already exist in another OU. Either delete or move it before joining" -foregroundcolor red -backgroundcolor yellow}
- }
- "1326" { Write-Host "Wrong username or password" -foregroundcolor red -backgroundcolor yellow }
- "2691" { Write-Host "Computer is already joined to this OU" -foregroundcolor red -backgroundcolor yellow }
- "0" { Write-Host "Computer was joined"-foregroundcolor Green }
- default { Write-Host "Undetermined error: $ret" }
- }
- }
- else { write-host "Computer was not renamed. Try again ($counter/3)" }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement