Advertisement
Guest User

Untitled

a guest
Jun 26th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. $domain = "our.domain.com"
  2. $DomainJoin = 1
  3. $CreateAccount = 2
  4. $AllowJoinIfAlreadyJoined = 32
  5. $user = $credentials.username
  6. $pass = ($credentials.getnetworkcredential()).password
  7. $computer = get-wmiobject Win32_ComputerSystem
  8.  
  9. $ret = $computer.rename($computername,$credentials.getnetworkcredential()).password,$credentials.username)
  10. if ($ret.ReturnValue -eq 0)
  11. {
  12. $ret = $computer.JoinDomainOrWorkGroup($domain,($credentials.GetNetworkCredential()).Password, $credentials.UserName, $OU, 0x1 + 0x2 + 0x20 + 0x400)
  13.  
  14. Switch ($ret.ReturnValue)
  15. {
  16. "2224" {
  17. $ret = $computer.JoinDomainOrWorkGroup($domain,$pass,$user,$OU,33)
  18. if ($ret.ReturnValue -eq 1332) { write-host "Computer already exist in another OU. Either delete or move it before joining" -foregroundcolor red -backgroundcolor yellow}
  19. }
  20. "1326" { Write-Host "Wrong username or password" -foregroundcolor red -backgroundcolor yellow }
  21. "2691" { Write-Host "Computer is already joined to this OU" -foregroundcolor red -backgroundcolor yellow }
  22. "0" { Write-Host "Computer was joined"-foregroundcolor Green }
  23. default { Write-Host "Undetermined error: $ret" }
  24. }
  25. }
  26. else { write-host "Computer was not renamed. Try again ($counter/3)" }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement