Before you start
Objectives: Learn commands which are used to configure Windows Server 2012 machines from the command line.
Prerequisites: no prerequisites.
Key terms: Windows Server 2012 Core, configuration, command line, powershell, initial configuration
Server Core
As you should know, to configure server core we will mostly use PowerShell or CMD. In PowerShell we can use most commands that are available in CMD (they are enabled trough aliases).
Hostname Configuration
So, the first thing we should know is the hostname of our computer. To check the hostname we can enter the command:
hostname
To change the computer name, we can enter the command:
netdom renamecomputer <currentName> /NewName:<newName> /userd:<adminUser> /passwordd: /reboot:0
To rename the computer we will have to enter the current name of the computer, and then specify the user with administrative privileges. Note that we didn’t enter the password in the command, but we will be prompted for it. The /reboot:0 means that the system will reboot 0 seconds after the command executes. The command “ipconfig /all” will also show us the computer name. If we don’t know the current hostname, we can use the command:
etdom renamecomputer %computername% /NewName:<newName>
Network Interface Configuration
To configure basic IP properties we can use NetShell command line tool. The first thing we should know is what interfaces we have. To find this out for IPv4 interfaces we can enter the command:
netsh interface ipv4 show interfaces
This command will list all interfaces and show the index (Idx) and name of each interface, like this:
Show Interfaces Command
To check the current IP configuration we can enter the command:
ipconfig /all
Next, to set a static IP address on Ethernet interface, we would enter the command:
netsh interface ipv4 set address name=Ethernet source=static address=192.168.77.10 mask=255.255.255.0 gateway=192.168.77.2
So, in our example we have configured IPv4 interface with the name Ethernet. The address will be static, and the address we want is 192.168.77.131 / 24 (class C subnet mask). We have also configured default gateway.
The next thing to configure is the DNS server. The command to do that is:
netsh interface ipv4 add dnsserver name=Ethernet address=192.168.77.2 index=1
Again we have to specify the name of the interface to configure and then set the IP address of the DNS server. In our case, the IP of the DNS server is the same as the default gateway. The “index=1” means that this will be our primary DNS server.
Domain and User Accounts
To join our computer to the domain we can enter the command:
netdom join %computername% /domain:<domainName> /userd:<adminUser> /passwordd: /reboot:0
We should also add user accounts so that we don’t have to use default Administrator account. To do that we can enter the command:
net user <userName> /add *
So we have to specify the name of our new user and use the /add switch. If we enter the *, we will be prompted to specify the user password right now. If we don’t use *, the user will have to specify the password during first log on.
To add some user to our local group, we can enter the command:
net localgroup <groupName> /add <userName>
For example, if we want to add user UWAdmin to the group Administrators, we would enter the command: “net localgroup Administrators /add UWAdmin”. If we want to add a domain user to the local group, we only need to specify the domain on which the user is located.
net localgroup <groupName> /add <domainName>\<userName>
To check the information about the user, we can enter the command:
net user <userName>
Sconfig
The sconfig actually came with the Windows Server 2008 R2, and is a great way to configure our servers. Sconfig is also executed in CMD, but it uses a menu system so it’s easy to work with. To enable sconfig we simply enter the “sconfig” in CMD and hit enter. After that we will see the screen like this:
sconfig Tool
All we have to do now is enter the menu number in order to see more options and to configure certain option. For example, let’s change Windows Update Settings from manual to automatic. To do that we first enter number 5 to select Windows Update Settings from the menu. Then we get a message that we can enter A for automatic or M for manual. We have entered A and hit enter.
Example Configuration in sconfig
Another thing we can configure is how our server will respond to ping. We can do that in menu item 4 (“Configure Remote Management”), and then menu item 3 (“Configure Server Response to Ping”). I usually like to turn it on so I can check network conectivity using ping command. This setting actually configures the firewall to allow ping.
The important thing you should get from this tutorial is that the sconfig tool exists, and that you understand how to use it. Using Sconfig is a great and quick way to configure important settings for our server.
Firewall
As you know, we can remotely connect to a Server Core machine and manage it remotely. For this to work we have to make sure that our firewall will allow this. In order to do that we can enter the command:
netsh advfirewall firewall set rule group=”Remote Administration” new enable=yes
To disable the firewall, we can enter the command:
netsh advfirewall set allprofiles state off
Keep in mind that you should disable Windows firewall only if you have a third party firewall, or hardware firewall installed, or if you want to temporarily test something (like network applications or similar).
To reset all firewall settings we can enter the command:
netsh advfirewall reset
This command will bring up all the default firewall settings.
Other Useful Commands
Enable remote desktop:
cscript c:\windows\system32\scregedit.wsf /ar 0
Restart the computer:
shutdown /r /t 0
Open Task Manager:
taskmgr
List running services:
net start
List running tasks:
tasklist
Activate PowerShell in CMD:
powershell