PoshCode Archive  Artifact [38fab9afaa]

Artifact 38fab9afaadcaa7d23e70b08d3ef9e38b785632876cc2eba1eac7e5859106ea1:

  • File COE_IMAGE.ps1 — part of check-in [12379df108] at 2018-06-10 13:11:34 on branch trunk — A function to rename a computer (user: Gerald Klassen size: 946)

# encoding: ascii
# api: powershell
# title: COE_IMAGE
# description: A function to rename a computer
# version: 0.1
# type: function
# author: Gerald Klassen
# license: CC0
# function: Set-ComputerName
# x-poshcode-id: 2507
# x-archived: 2016-05-20T10:20:55
# x-published: 2011-02-15T13:30: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)
	}