Thursday, June 18, 2015

Managing Windows Server 2012 R2 Using PowerShell : Part-6 : Checking if server is member of domain or not.

 

  1. Part 1 : Windows Server 2012 R2 Installation.
  2. Part 2 : Exploring PowerShell Default Settings.
  3. Part 3 : Getting and setting server name.
  4. Part 4 : Getting IP Address of the server.
  5. Part 5 : Setting IP Address of the server.

Configuration

Part - 6 { Domain Membership.}

In the previous blog post, we have seem, that how can we set a static IP address in our Windows 2012 R2 Server by using PowerShell.

Our next step is to find is server is the member of our domain environment or not.

Checking Domain membership( the non-PowerShell way )

There are few ways to check domain membership.

  • Manually.
    • lol.!
  • By using Net.exe command.
    • Open command prompt and run the below command.
    • net config workstation
    • 6-19-2015 9-59-30 AM
    • In the above screenshot, you can see , it is showing us "workstation domain" and it's value is "workgroup" and we know, this is not our domain name.

Checking Domain membership ( The PowerShell way )

Now let's check if  our server is member of domain or not by using PowerShell.

There are quite few ways to check if you server is member of domain or not.

Just for your information or knowledge there are few PowerShell environment variable which you should be aware of, in writing script for server, they become very handy.

  • $env:USERDNSDOMAIN
    • This environment variable contains the name of your domain DNS name. If your server is part of domain.
      • My laptop is part of domain, this variable do exist of my laptop, but this variable is not available of our server. So I am assuming,that it created after joining of domain. 
  • Using WMI Class Win32_Computersystem
    • The best way to check, if server is part of domain or not, is by using the Win32_Computersystem class.
    • Get-WmiObject -Class Win32_ComputerSystem
    • Run the above command, and you will see a lot of information related to domain joining.
    • 6-19-2015 10-16-13 AM
    • Like
      • Name of Workgroup.
      • Name of Domain.
      • Domain Role.

Now, you must be thinking, that how you can simple check, with Yes / No, if the server is part of domain or not. It's easy, the above output, has a property named "PartOfDomain", if your server is part of domain the value contains true otherwise it will  contain false.

Run the below command and see the output.

(Get-WmiObject -Class Win32_ComputerSystem).PartOfDomain 

 

6-19-2015 10-23-30 AM

 

In the above screenshot, you can see that output of above command is false, that means our server is not a member of domain yet.

 

Now, in next blog post, we will see, how can we add our sever to the domain.

 

Wishing you all the best and have fun.

 

Aman Dhally, Manya Kaur, Manya Dhally,

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

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.