PoshCode Archive  Artifact Content

Artifact c1c421fa927a7902d49e64a0349c05e3939f53d2d4c7ee5e2704ca3cd038b8ed:

  • File Set-Computername.ps1 — part of check-in [d7ded013f8] at 2018-06-10 13:19:09 on branch trunk — A function to rename a computer (user: BORGKLS1 size: 947)

# encoding: ascii
# api: powershell
# title: Set-Computername
# description: A function to rename a computer
# version: 0.1
# type: function
# author: BORGKLS1
# license: CC0
# function: Set-ComputerName
# x-poshcode-id: 3033
# x-archived: 2012-01-14T07:06:35
# x-published: 2012-11-01T04:20:00
#
# Andy Schneider
# get-powershell.com
# Add capability to change name on remote PC and Update Usage statement
# Gerald Klassen
#
function Set-ComputerName {
	param(	[switch]$help,
		[string]$originalPCName=$(read-host "Please specify the current name of the computer"),
		[string]$computerName=$(read-host "Please specify the new name of the computer"))
			
	$usage = "set-ComputerName -originalPCname CurrentName -computername AnewName"
	if ($help) {Write-Host $usage;break}
	
	$computer = Get-WmiObject Win32_ComputerSystem -OriginalPCname OriginalName -computername $originalPCName
	$computer.Rename($computerName)
	}