PoshCode Archive  Artifact Content

Artifact ed7482625d2052fd4cd8ff382c0a6afd8828de5aa74826fffbe03f138ddd2504:

  • File lol.ps1 — part of check-in [6e9c8a1585] at 2018-06-10 13:13:02 on branch trunk — A function to rename a computer (user: Gerald Klassen size: 940)

# encoding: ascii
# api: powershell
# title: lol
# description: A function to rename a computer
# version: 0.1
# type: function
# author: Gerald Klassen
# license: CC0
# function: Set-ComputerName
# x-poshcode-id: 2605
# x-archived: 2011-04-10T07:06:26
# x-published: 2011-04-06T12:43: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)
	}