Skip to content

Instantly share code, notes, and snippets.

@SweetAsNZ
Last active February 2, 2022 17:04
Show Gist options
  • Save SweetAsNZ/5a781fd5d78b4e9a290dccfedec75a10 to your computer and use it in GitHub Desktop.
Save SweetAsNZ/5a781fd5d78b4e9a290dccfedec75a10 to your computer and use it in GitHub Desktop.
Rename Remote PC
Function Rename-PC{
[CmdletBinding()]
param(
[Parameter(Mandatory=$false)]
[string]$OldPCName,
[Parameter(Mandatory=$false)]
[string]$NewPCName,
)
$Cred = Get-Credential -UserName "$($env:USERDOMAIN)\$($env:USERNAME)" -Message "Domain\UserName & Password"
# Using Read-Host as it is the team's Preference. Left parameters above in case people prefer that they can comment the following 2 lines out.
$OldPCName = Read-Host "Old PC Name?"
$NewPCName = Read-Host "New PC Name?"
#$OldPCName = 'PC1'
#$NewPCName = 'PC2'
Invoke-Command -ComputerName $OldPCName -ArgumentList $NewPCName, $Cred -ScriptBlock{
param($NewPCName,$Cred) # The Order Is Important
Rename-Computer -NewName $NewPCName -DomainCredential $Cred -Verbose
}
$Cred = $null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment