Thursday, 1 January 2009

Get-Domain


  1. <# 
  2. .SYNOPSIS 
  3.     Shows use of GetCurrentDomain to return information about the domain 
  4. .DESCRIPTION 
  5.     Uses system.directoryservices.activedirectory.domain and GetCurrentDomain 
  6.     to return domain information of the currently logged on user. Note that this 
  7.     domain may be different to the domain of the computer itself. 
  8. .NOTES 
  9.     File Name  : get-domain.ps1 
  10.     Author     : Thomas Lee - tfl@psp.co.uk 
  11.     Requires   : PowerShell V2 CTP3 
  12. .LINK 
  13.     http://www.pshscripts.blogspot.com 
  14. .EXAMPLE 
  15.     PS c:\foo> .\get-domain.ps1 
  16.     You are connected to the cookham.net domain 
  17.     Role Holders in this domain: 
  18.       PDC Role Holder     :  Cookham1.cookham.net 
  19.       RID Role Holder     :  Cookham1.cookham.net 
  20.       InfraM Role Holder  :  Cookham1.cookham.net 
  21. #> 
  22.  
  23. ### 
  24. # Start of script 
  25. ### 
  26.  
  27. # Get Domain information 
  28. $domain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()  
  29.  
  30. # Display information    
  31.    "You are connected to the {0} domain" -f $domain.name  
  32.    "Role Holders in this domain:" 
  33.    "  PDC Role Holder     :  {0}" -f $domain.PdcRoleOwner 
  34.    "  RID Role Holder     :  {0}" -f $domain.RIDRoleOwner 
  35.    "  InfraM Role Holder  :  {0}" -f $domain.InfrastructureRoleOwner 
  36. # End of script    

2 comments:

Unknown said...

You probably should use GetComputerDomain() instead of GetCurrentDomain(). The one you used returned the domain of the currently logged in user instead of domain the computer joined to.

Thomas Lee said...

The script was meant to show the use of GetCuttentDomain. I have entered a separate script for GetComputerDomain. Thanks for the heads up!