PoshCode Archive  Artifact [d0341e067b]

Artifact d0341e067bf062c6a29a557d5f3d2b2cdec03f4adf53cce2484d1385faaccd27:

  • File Set-Computername.ps1 — part of check-in [b4320efb30] at 2018-06-10 12:57:39 on branch trunk — A function to rename a computer (user: Gerald Klassen size: 972)

# 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: 1476
# x-archived: 2011-03-26T11:30:00
# x-published: 2011-11-18T12:37:00
#
# Andy Schneider
# get-powershell.com
# Corrected syntax to change name on remote PC
# 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 -computername $originalPCName
	$computer.Rename($computerName)
	}