Part - 3 { Information - Server Names }
In the pervious blog post, we explored few default settings and configurations of the PowerShell on the newly installed "Windows Server 2012 R2". Today we are going to explore it a little bit more.
Getting Server Name
The first thing after installing server is to either check it's computer name, or, set it's name. You must be thinking that, there should be some PowerShell cmdlet , to check the name of the server.
Arrr! No, you are wrong! There is no cmdlet to check Server name. We have a cmdlet to rename server name, but not to check the current name.
Now the question arise, "How will check the server name?", There are two-three ways to check the existing name of the server.
- By using $env:COMPUTERNAME variable in the PowerShell console. this variable stores the name of the machine.
- The another way to find is to run the Hostname.exe command.
- The another way to use the WMI, the WMI class name Win32_ComputerSystem , has a Name property which contains the name of the server .
- (Get-WmiObject Win32_ComputerSystem).Name
Renaming Server Name
After getting the name of the server, what is my next step is ? Guess! Guess!?, my next step is to rename the server name to something logical, and off-course, we are going to set computer name using PowerShell.
We are going to change the name of the server from "WIN-FOUM1FCL4JB" to "Del-2k12"
To rename the computer name , we do use the Rename-Computer cmdlet. To rename the server name, I have used the below command. In parameter -NewName we have provided the new desired name for our server.
Rename-Computer -NewName 'Del2k12'
In the above screenshot you can see that our command has run successfully and it is asking to restart the computer to change to take effect.
We can restart the server, but, restart it with a PowerShell cmdlet Restart-Computer .
Once the computer is restart and I logged in again and when I checked the name of the server, it is set to "DEL-2k12"... Great!
That's all for today's blog post, we will see and do more in the next blog post.
Take care!
Aman Dhally
If you like, you can follow me on Twitter and Facebook. You can also check my “You Tube” channel for PowerShell video tutorials. You can download all of my scripts from “Microsoft TechNet Gallery”.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.