Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Set-ExecutionPolicy -ExecutionPolicy Unrestricted
- Write-Host "Importing AutoLogon and Get-DomainComputer modules"
- Import-Module -Name ".\Set-AutoLogon.psm1"
- Import-Module -Name ".\Get-DomainComputer.psm1"
- Write-Host "Copying required files to Temp"
- Copy-Item -Path ".\join.ps1" -Destination "C:\Temp"
- Copy-Item -Path ".\username.txt" -Destination "C:\Temp"
- Copy-Item -Path ".\password.txt" -Destination "C:\Temp"
- Write-Host "Importing credentials"
- $username = get-content "C:\Temp\username.txt"
- $password = get-content "C:\Temp\password.txt"
- $password = convertto-securestring $password -asplaintext -force
- $creds = New-Object System.Management.Automation.PSCredential($username,$password)
- Write-Host "Retrieving latest computer name from AD"
- $name = Get-DomainComputer -ComputerName "Computer*" -credential $creds -SizeLimit 100 -DomainDN "LDAP://pathto/dc=corp,dc=contoso,dc=com" | select-object -expandproperty name -last 1
- Write-Host "Incrementing computer name by one"
- $digitString = $name -replace 'Computer'
- $number = [int]$digitString
- $newNumber = $number + 1
- $newDigitString = $newNumber.ToString().padLeft(3, '0')
- $computername = "Computer$newDigitString"
- Write-Host "New computer name will be $computername"
- Write-Host "`n"
- Write-Host "Setting new computer name to $computername"
- $ComputerInfo = Get-WmiObject -Class Win32_ComputerSystem
- $ComputerInfo.Rename($computername)
- Write-Host "Writing new computer name to file"
- add-content -path ".\computername.txt" -value $computername
- Write-Host "Setting AutoLogon for next boot, executing join script after logon"
- Set-AutoLogon -DefaultUsername ".\Administrator" -DefaultPassword "PASSWORD" -AutoLogonCount "1" -Script "c:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -noexit -File C:\Temp\join.ps1"
- Write-Host "Rebooting in 15 seconds..."
- #Rearm and check activation just in case, since we've just imaged the computer.
- slmgr /rearm
- slmgr /ato
- start-sleep -seconds 15
- restart-computer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement