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!



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

Wednesday, May 13, 2015

Managing Windows Server 2012 R2 Using PowerShell : Part-2 : Exploring PowerShell Default Settings.

Part 1 : Windows Server 2012 R2 Installation

Part -2

In the Part-1 of this series, we have done a fresh installation of "Windows Server 2012 R2".  That covers our "Installation" section of this tutorial series.
Next section of the series is getting various Information of the server by using PowerShell. In this Section we are going to get some basic and default information of the server.


Let's try to dig some basic information of our newly server using PowerShell. but before exploring anything else let's explore the PowerShell first.
(This server is not joined to domain yet. So everything is set to default as-it-is come.)

1. Information regarding PowerShell

You will see the PowerShell shortcut in the taskbar ( that's cool ). Click on icon to Open PowerShell Console.
5-13-2015 12-12-41 PM
When you open PowerShell console, you will notice, that the PowerShell console is opens in the "Administrator" mode by default. (nice!)
5-13-2015 12-17-14 PM
First thing to check is the default version of PowerShell which come along with "Windows Server 2012 R2", to check the version of  PowerShell , we type and enter the variable name $PSVersionTable , this variable contains the information of PowerShell version.
5-13-2015 12-15-43 PM
In the above output we can see that the value of "PSVersion" (PowerShell Version) is 4.0. That means "Server 2012 R2" shipped with PowerShell version 4.0 installed.
I also want to check, ( Just out of my curiosity), how many cmdlets are there in PowerShell by default in "Server 2012 R2". Total cmdlets are easy to calculate by using Get-Command and brackets and dot notation.

5-13-2015 12-26-08 PM

1311, Wow!, PowerShell on "Windows Server 2012 R2" contains 1,311 ( One thousand, Three Hundred and Eleven cmdlets) by default.
Now, I need to check what is Execution policy is set to ( I am assuming  it might be set to Restricted, but worth checking still.). To check we Execution policy we use the  Get-ExecutionPolicy ".
5-13-2015 12-33-05 PM
Oh! I my assumptions was wrong, the Execution Policy is set to "RemoteSigned" by default. Nice! ( told you, that's it always worth checking.)
Let's check about how many PowerShell modules are installed by default.  Checking the total count is simple, Brackets and dot notation is our best friends.
(Get-Module -ListAvailable * ).count
5-13-2015 12-50-34 PM

63 Modules, PowerShell modules are there. Cool.!
Now, the last thing to check , if PowerShell-ISE is available by default or not.  When I searched for "PowerShell ISE" in search charm, I have found it Smile .

5-13-2015 1-21-38 PM
So, we can conclude everything in the below table.
PowerShell Default Information on Windows Server 2012 R2
Default Version
Number Total PowerShell Cmdlets
PowerShell Execution Policy
Number of Default Modules
PowerShell ISE available by default
Below is the name and version of all of Modules those are available on my "Server 2012 R2" installation by default.
Name and Version Number of all PowerShell Modules
S.NO Name Version ModuleType
1 AppLocker Manifest
2 Appx Manifest
3 BestPractices 1.0 Manifest
4 BitsTransfer Manifest
5 BranchCache Manifest
6 CimCmdlets Manifest
7 DirectAccessClientComponents Manifest
8 Dism 3.0 Script
9 DnsClient Manifest
10 International Manifest
11 iSCSI Manifest
12 IscsiTarget Manifest
13 ISE Script
14 Kds Manifest
15 Microsoft.PowerShell.Diagnostics Manifest
16 Microsoft.PowerShell.Host Manifest
17 Microsoft.PowerShell.Management Manifest
18 Microsoft.PowerShell.Security Manifest
19 Microsoft.PowerShell.Utility Manifest
20 Microsoft.WSMan.Management Manifest
21 MMAgent 1.0 Manifest
22 MsDtc Manifest
23 NetAdapter Manifest
24 NetConnection Manifest
25 NetEventPacketCapture Manifest
26 NetLbfo Manifest
27 NetNat Manifest
28 NetQos Manifest
29 NetSecurity Manifest
30 NetSwitchTeam Manifest
31 NetTCPIP Manifest
32 NetworkConnectivityStatus Manifest
33 NetworkTransition Manifest
34 NFS 1.0 Manifest
35 PcsvDevice Manifest
36 PKI Manifest
37 PrintManagement 1.1 Manifest
38 PSDesiredStateConfiguration 1.0 Manifest
39 PSDiagnostics Script
40 PSScheduledJob Binary
41 PSWorkflow Manifest
42 PSWorkflowUtility Manifest
43 RemoteDesktop Manifest
44 ScheduledTasks Manifest
45 SecureBoot Manifest
46 ServerCore Script
47 ServerManager Script
48 ServerManagerTasks Cim
49 SmbShare Manifest
50 SmbWitness Manifest
51 SoftwareInventoryLogging Manifest
52 StartScreen Manifest
53 Storage Manifest
54 TLS Manifest
55 TroubleshootingPack Manifest
56 TrustedPlatformModule Manifest
57 UserAccessLogging Manifest
58 VpnClient Manifest
59 Wdac Manifest
60 Whea Manifest
61 WindowsDeveloperLicense Manifest
62 WindowsErrorReporting 1.0 Script
63 WindowsSearch Manifest
That's all for now, In the next blog post, we will explore more information with the help of PowerShell.
chaar Sahibzaade
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”.