PoshCode Archive  Artifact Content

Artifact 4b9d5399e27262b54a6aa5a83f8ac407ca872155af15d4966e999a54857131e8:

  • File Set-Computername.ps1 — part of check-in [0f277b74d6] at 2018-06-10 14:04:11 on branch trunk — A function to rename a computer (user: Gerald Klassen size: 953)

# encoding: ascii
# api: powershell
# title: Set-Computername
# description: A function to rename a computer
# version: 0.1
# type: function
# author: Gerald Klassen
# license: CC0
# function: Set-ComputerName
# x-poshcode-id: 5923
# x-archived: 2015-07-10T13:21:17
# x-published: 2015-07-08T16:23: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)
	}