Tuesday, 1 June 2010

Get-ComputerDomain.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     Shows use of GetComputerDomain to return information about the domain 
  4. .DESCRIPTION 
  5.     Uses system.directoryservices.activedirectory.domain and GetComputerDomain 
  6.     to return domain information of the Computer. Note that this 
  7.     may be different to the domain of the logged on user.    
  8. .NOTES 
  9.     File Name  : Get-DomainController.ps1 
  10.     Author     : Thomas Lee - tfl@psp.co.uk 
  11.     Requires   : PowerShell V2 CTP3 
  12. .LINK 
  13.    This script posted to: 
  14.         http://pshscripts.blogspot.com/2010/06/get-computerdomainps1.html 
  15.     MSDN Sample posted at: 
  16.         http://msdn.microsoft.com/en-us/library/system.directoryservices.activedirectory.domain.getcomputerdomain%28VS.80%29.aspx  
  17. .EXAMPLE 
  18.     PS c:\foo> .\Get-ComputerDomain.ps1 
  19.     Your computer is a member of the cookham.net domain 
  20.     Role Holders in this domain: 
  21.       PDC Role Holder     :  Cookham1.cookham.net 
  22.       RID Role Holder     :  Cookham1.cookham.net 
  23.       InfraM Role Holder  :  Cookham1.cookham.net 
  24. #> 
  25.   
  26. ### 
  27. # Start of script 
  28. ### 
  29.   
  30. # Get Domain information using static method 
  31. $domain = [System.DirectoryServices.ActiveDirectory.Domain]::GetComputerDomain()  
  32.  
  33. # Display information for current computer 
  34. "Your computer is a member of the {0} domain" -f $domain.name  
  35. "Role Holders in this domain:" 
  36. "  PDC Role Holder     :  {0}" -f $domain.PdcRoleOwner 
  37. "  RID Role Holder     :  {0}" -f $domain.RIDRoleOwner 
  38. "  InfraM Role Holder  :  {0}" -f $domain.InfrastructureRoleOwner 
  39. # End of script    

No comments: