20 lines
701 B
PowerShell
20 lines
701 B
PowerShell
Function Get-PCRename($ComputerName){
|
|
|
|
if(Test-Connection -ComputerName $ComputerName -Count 1)
|
|
{
|
|
$User = $env:username
|
|
$DomainUser = "int\$User"
|
|
|
|
Write-Host "Current Hostname: $ComputerName"
|
|
$NewHostName = Read-Host "New Hostname"
|
|
|
|
Rename-Computer -ComputerName $ComputerName -NewName $NewHostName -DomainCredential $DomainUser -force -Restart
|
|
Write-Host "Renamed PC, successful. Restarting PC... Old Hostname: $ComputerName, New Hostname: $NewHostName" -ForegroundColor Green
|
|
|
|
}else{
|
|
|
|
Write-Host "Unable to connect to PC...Cancelling PCRename script on $ComputerName" -ForegroundColor Red
|
|
}
|
|
|
|
}
|