Windows10Deployment/Set-ComputerName.ps1

39 lines
1.7 KiB
PowerShell
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 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) {
Write-Host "$($Computer.CN) $($Computer.MAC) $thisComputerMac"
If ($thisComputerMAC -match $Computer.MAC) {
Write-Host "$($Computer.CN) matches the localhost MAC Address: $thisComputerMAC"
$NewComputerName = $Computer.CN
}
}
# if computer isnt 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"
}
$cred = New-Object System.Management.Automation.PsCredential("SAWTOOTH\Administrator", (ConvertTo-SecureString "REPLACE_WITH_PASSWORD" -AsPlainText -Force))
# rename computer and join to domain
Write-Host "Computer will be renamed to $NewComputerName."
Rename-Computer -NewName $NewComputerName -Force -Verbose
Add-Computer -Force -DomainName sawtooth.claremontmakerspace.org -Options JoinWithNewName -Credential $cred
#Start-Sleep -Seconds 5
#Restart-Computer
# Install Salt
# Write-Host "Installing Salt with minion name: $NewComputerName."
# \\ucs\Software\Salt-Minion-2019.2.2-Py3-AMD64-Setup.exe /S /minion-name="$NewComputerName"