Last active
February 2, 2022 17:04
-
-
Save SweetAsNZ/5a781fd5d78b4e9a290dccfedec75a10 to your computer and use it in GitHub Desktop.
Rename Remote PC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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