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

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

INFORMATION

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.
(Get-Command).count

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