PoshCode Logo PowerShell Code Repository

lol by Kaimaani 10 months ago (modification of post by Gerald Klassen view diff)
diff | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/2605"></script>download | new post

A function to rename a computer
Andy Schneider
get-powershell.com

Add capability to change name on remote PC and Update Usage statement
Gerald Klassen

  1. function Set-ComputerName {
  2.         param(  [switch]$help,
  3.                 [string]$originalPCName=$(read-host "Please specify the current name of the computer"),
  4.                 [string]$computerName=$(read-host "Please specify the new name of the computer"))
  5.                        
  6.         $usage = "set-ComputerName -originalPCname CurrentName -computername AnewName"
  7.         if ($help) {Write-Host $usage;break}
  8.        
  9.         $computer = Get-WmiObject Win32_ComputerSystem -OriginalPCname OriginalName -computername $originalPCName
  10.         $computer.Rename($computerName)
  11.         }

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me