PoshCode Archive  Artifact Content

Artifact 17542f1dcdbe81a44c14c47231b810586e94d2b33c85832bd4f2d1caee2390b5:

  • File Set-Computername.ps1 — part of check-in [4b6f9b217e] at 2018-06-10 13:54:56 on branch trunk — A function to rename a computer (user: Gerald Klassen size: 979)

# 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: 541
# x-derived-from-id: 1476
# x-archived: 2016-05-21T13:14:22
# x-published: 2009-08-20T15:51: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)
	}