Wednesday, December 8, 2010

Powershell set computer name

I will be posting some powershell scripts that have been found in places that I did not remember. Some have been tweeked by me others have not.


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)

}

No comments: