Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2018
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. Set-ExecutionPolicy -ExecutionPolicy Unrestricted
  2. Write-Host "Importing AutoLogon and Get-DomainComputer modules"
  3. Import-Module -Name ".\Set-AutoLogon.psm1"
  4. Import-Module -Name ".\Get-DomainComputer.psm1"
  5. Write-Host "Copying required files to Temp"
  6. Copy-Item -Path ".\join.ps1" -Destination "C:\Temp"
  7. Copy-Item -Path ".\username.txt" -Destination "C:\Temp"
  8. Copy-Item -Path ".\password.txt" -Destination "C:\Temp"
  9. Write-Host "Importing credentials"
  10. $username = get-content "C:\Temp\username.txt"
  11. $password = get-content "C:\Temp\password.txt"
  12. $password = convertto-securestring $password -asplaintext -force
  13.  
  14. $creds = New-Object System.Management.Automation.PSCredential($username,$password)
  15. Write-Host "Retrieving latest computer name from AD"
  16. $name = Get-DomainComputer -ComputerName "Computer*" -credential $creds -SizeLimit 100 -DomainDN "LDAP://pathto/dc=corp,dc=contoso,dc=com" | select-object -expandproperty name -last 1
  17. Write-Host "Incrementing computer name by one"
  18. $digitString = $name -replace 'Computer'
  19. $number = [int]$digitString
  20. $newNumber = $number + 1
  21. $newDigitString = $newNumber.ToString().padLeft(3, '0')
  22. $computername = "Computer$newDigitString"
  23. Write-Host "New computer name will be $computername"
  24. Write-Host "`n"
  25.  
  26. Write-Host "Setting new computer name to $computername"
  27. $ComputerInfo = Get-WmiObject -Class Win32_ComputerSystem
  28. $ComputerInfo.Rename($computername)
  29.  
  30. Write-Host "Writing new computer name to file"
  31. add-content -path ".\computername.txt" -value $computername
  32.  
  33. Write-Host "Setting AutoLogon for next boot, executing join script after logon"
  34. Set-AutoLogon -DefaultUsername ".\Administrator" -DefaultPassword "PASSWORD" -AutoLogonCount "1" -Script "c:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -noexit -File C:\Temp\join.ps1"
  35.  
  36. Write-Host "Rebooting in 15 seconds..."
  37. #Rearm and check activation just in case, since we've just imaged the computer.
  38. slmgr /rearm
  39. slmgr /ato
  40. start-sleep -seconds 15
  41. restart-computer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement