Monday, June 15, 2015

Managing Windows Server 2012 R2 Using PowerShell : Part-4 : Getting IP Address of the Server.

  1. Part 1 : Windows Server 2012 R2 Installation.
  2. Part 2 : Exploring PowerShell Default Settings.
  3. Part 3 : Getting and setting server name.

5-14-2015 12-24-07 PM[3]

Part - 4 { Information - IP Addresses}

 

In our pervious blog post, we have learned, that how can we get and set the name of "Windows 2012" server.

 

Now, our next step is to find the IP Address of our current server and change it according to our requirements.

 

In "Windows Server 2012" we have a nice set of PowerShell modules, those deals with networking stuff. We can use the Get-Module cmdlet, to get the list of all modules, whose names start with NET.

 

 

Get-Module -ListAvailable *net*

 

6-15-2015 11-46-51 AM

 

Getting current IP Address (the old way).

There are several ways to get the current IP Address of the server. We can get it by using WMI, external commands, and using PowerShell too.

  1. By using ipconfig
    1. ipconfig / all
  2. By using netsh command
    1. netsh interface ip show config name="Ethernet"
  3. By using WMI Query
    1. Get-WmiObject -Query "SELECT IPAddress FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'True'"

Getting current IP Address (the new way).

Ok, we all knows, that PowerShell is a object based language, and it's so cool, in Windows 2012, we have a amazing, nice cmdlet which give us the information of current IP Address.  The cmdlet is called, Get-NetIPConfiguration

Just runt the above cmdlet and it will give you all the information related of our IP-address.

6-15-2015 12-18-13 PM

Cool , No? In the next blog post, we will see about setting IP-Address using PowerShell. Till then take care.

tumblr_m7qsb5MDXF1qavhj0o1_500

Regards.
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”.

Thursday, May 14, 2015

Managing Windows Server 2012 R2 Using PowerShell : Part-3 : Getting and Setting Server Name.

 

    1. Part 1 : Windows Server 2012 R2 Installation.
    2. Part 2 : Exploring PowerShell Default Settings.

5-14-2015 12-24-07 PM

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.

5-14-2015 12-35-03 PM

Now the question arise, "How will check the server name?",  There are two-three ways to check the existing name of the server.

  1. By using  $env:COMPUTERNAME variable in the PowerShell console. this variable stores the name of the machine.
  2. 5-14-2015 12-44-00 PM
  3. The another way to find is to run the Hostname.exe command.
  4. 5-14-2015 12-54-08 PM
  5. The another way to use the WMI, the WMI class name Win32_ComputerSystem , has a Name property which contains the name of the server .
  6. (Get-WmiObject Win32_ComputerSystem).Name
  7. 5-14-2015 12-57-29 PM

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'

5-14-2015 1-05-01 PM

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 .

5-14-2015 1-05-35 PM

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!

5-14-2015 1-06-54 PM

That's all for today's blog post, we will see and do more in the next blog post.

Take care!

816

 

Regards.
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”.