PoshCode Archive  Artifact Content

Artifact 17fe946b4b940c3f9ca6b6fd8277f3f062576141b15630023410b66eb96932a2:

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

# 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: 540
# x-archived: 2011-03-26T11:57:10
# x-published: 2011-08-20T15:46:00
#
# Andy Schneider
# get-powershell.com
# Add capability to change name on remote PC
#
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 -computername AnewName"
	if ($help) {Write-Host $usage;break}
	
	$computer = Get-WmiObject Win32_ComputerSystem -computername $originalPCName
	$computer.Rename($computerName)
	}