PoshCode Archive  Artifact [bd1f3583c2]

Artifact bd1f3583c2ee1288e162bfdc1ec814ca98a2d7c169a7c32b088780a48d1cd093:

  • File Set-Computername.ps1 — part of check-in [034011d604] at 2018-06-10 13:10:55 on branch trunk — A function to rename a computer (user: DEEPSEADC01 size: 914)

# encoding: ascii
# api: powershell
# title: Set-Computername
# description: A function to rename a computer
# version: 0.1
# type: function
# author: DEEPSEADC01
# license: CC0
# function: Set-ComputerName
# x-poshcode-id: 2473
# x-archived: 2011-01-25T21:34:17
#
# 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)
	}