2019-12-17 10:26:44 -05:00
|
|
|
|
# Look up computer name from mac address in a file
|
|
|
|
|
# Based on Set-ComputerName from:
|
|
|
|
|
# https://kristopherjturner.com/2017/02/01/automating-computer-naming-after-deploying-windows-10-images/
|
|
|
|
|
|
|
|
|
|
$FileName = "ComputerList.csv"
|
|
|
|
|
|
|
|
|
|
$scriptPath = Split-Path $script:MyInvocation.MyCommand.Path
|
|
|
|
|
|
|
|
|
|
$thisComputerMAC = Get-WmiObject win32_networkadapterconfiguration -Filter 'ipenabled = "true"' | Select-Object MACAddress
|
|
|
|
|
$ComputerList = Import-Csv -Path "$scriptPath\$FileName"
|
|
|
|
|
|
|
|
|
|
# look up computer name by MAC address
|
|
|
|
|
ForEach ($Computer in $ComputerList) {
|
2020-01-03 19:17:30 -05:00
|
|
|
|
Write-Host "$($Computer.CN) $($Computer.MAC) $thisComputerMac"
|
2019-12-17 10:26:44 -05:00
|
|
|
|
If ($thisComputerMAC -match $Computer.MAC) {
|
|
|
|
|
Write-Host "$($Computer.CN) matches the localhost MAC Address: $thisComputerMAC"
|
|
|
|
|
$NewComputerName = $Computer.CN
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# if computer isn’t on list, ask for a name
|
|
|
|
|
If ($Null -eq $NewComputerName) {
|
|
|
|
|
Write-Host "Computer is not found in computer list." -ForegroundColor Red
|
|
|
|
|
$NewComputerName = Read-Host -Prompt "Please enter desired computer name then hit enter"
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-16 01:13:09 -04:00
|
|
|
|
$cred = New-Object System.Management.Automation.PsCredential("SAWTOOTH\DomainJoin", (ConvertTo-SecureString "REPLACE_WITH_PASSWORD" -AsPlainText -Force))
|
2020-01-03 19:17:30 -05:00
|
|
|
|
|
2022-09-16 01:09:50 -04:00
|
|
|
|
Write-Host "Waiting for RPC Service"
|
|
|
|
|
(Get-Service RpcSs).WaitForStatus("Running")
|
|
|
|
|
|
2020-01-03 19:17:30 -05:00
|
|
|
|
# rename computer and join to domain
|
2019-12-17 10:26:44 -05:00
|
|
|
|
Write-Host "Computer will be renamed to $NewComputerName."
|
2020-01-03 19:17:30 -05:00
|
|
|
|
Rename-Computer -NewName $NewComputerName -Force -Verbose
|
2022-09-16 01:11:28 -04:00
|
|
|
|
|
|
|
|
|
Write-Host "Waiting for RPC Service"
|
|
|
|
|
(Get-Service RpcSs).WaitForStatus("Running")
|
|
|
|
|
|
|
|
|
|
While($True){
|
|
|
|
|
try{
|
|
|
|
|
Write-Host "Trying to Domain Join"
|
|
|
|
|
Add-Computer -ErrorAction Stop -Force -DomainName sawtooth.claremontmakerspace.org -Options JoinWithNewName,InstallInvoke -Credential $cred
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
catch{
|
|
|
|
|
Write-Host $_
|
|
|
|
|
Start-Sleep -Seconds 1 # wait for a seconds before next attempt.
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-03 19:17:30 -05:00
|
|
|
|
|
|
|
|
|
# Install Salt
|
2022-09-16 01:13:22 -04:00
|
|
|
|
Write-Host "Installing Salt with minion name: $NewComputerName."
|
|
|
|
|
\\ucs.sawtooth.claremontmakerspace.org\Software\Salt-Minion-3004.2-Py3-AMD64-Setup.exe /S /minion-name="$NewComputerName"
|
2022-09-16 01:11:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#Read-Host -Prompt "Press Enter to reboot"
|
|
|
|
|
#Start-Sleep -Seconds 30
|
|
|
|
|
#Restart-Computer
|