Hi,
Yesterday I faced a problem in which I need to change the computer name using PowerShell. First I was looking for some cmdlet which can do this job for me but there is not any inbuilt cmdlet for it.
Then I searched and finally find a way by which I can do this within the PowerShell. This method is using WMI to do the task.
Download the script from Here : http://gallery.technet.microsoft.com/scriptcenter/Set-Computername-using-9cb6ecc4
Get-WmiObject Win32_ComputerSystem
We are using Get-WMI to give us all the value of Win32_ComputerSystem.
You can see in the Output that the "Name value contain our Computer name "WINANAL-088y8gx" with mach with our above screenshot.
$computerName = Get-WmiObject Win32_ComputerSystem
We are putting the command in to the $computerName variable. And you can see that the output of $computerName is same and above screenshot in which we run the command alone.
$name = Read-Host -Prompt "Please Enter the ComputerName you want to use."
In $name variables we are using Read-Host cmdlet with -Prompt argument with asking users to provide a computer name to be use.
Whatever user provide to Read-Host, the value is stored in the $name variable. In First example in below screenshot we didn't provide anything to Read-Host and you can see that output of $name is blank.
In next example we provide "Test-Laptop" to Read-Host and you can see that now $name contains the value of "Test-Laptop"
$computername.Rename($name)
Now check if you computer name get changed or not.
Bingo !!! Yes It is changed.. now reboot you laptop ;) using restart-Computer
And if you want a GUI box to to open a Pop-UP to insert computer Name try this
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
$name = [Microsoft.VisualBasic.Interaction]::InputBox("Enter Desired Computer Name ")
$name
Download the script from Here : http://gallery.technet.microsoft.com/scriptcenter/Set-Computername-using-9cb6ecc4
Thanks for reading .
Aman Dhally
What is
ReplyDeletewrite-host $([char]7)
supposed to do?
I don't see any output from it except blank lines. I'm just curious.
I don't understand $([char]7), because I thought [char]7 just cast the 7 as a char.
Hi,
Delete$([char]7) is a special character with do Beep.. Trun on your laptop speakers and then type and enter $([char]7) , you will hear a beep sound :)
thanks
aman
It looks like [char]7 is from an ASCII Table, but what symbol is it? Is it a blank?
ReplyDeleteI did it! I just follow the instruction you said, and viola I already set my computer name. Thanks for sharing.
ReplyDeleteSummer