Domain.GetComputerDomain Method
.NET Framework 2.0
Gets the Domain object that represents the domain to which the local computer is joined.
Namespace: System.DirectoryServices.ActiveDirectory
Assembly: System.DirectoryServices (in system.directoryservices.dll)
Assembly: System.DirectoryServices (in system.directoryservices.dll)
The return value of the GetComputerDomain method is a Domain object representing the domain to which the computer running the application is joined. This return value is independent of the credentials under which the application is run. To retrieve the Domain object that represents the domain corresponding to the user credentials in effect for the security context under which the application is running, use the GetCurrentDomain method instead.
Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.
Sample Using PowerShell
<#
.SYNOPSIS
Shows use of GetComputerDomain to return information about the domain
.DESCRIPTION
Uses system.directoryservices.activedirectory.domain and GetComputerDomain
to return domain information of the Computer. Note that this
may be different to the domain of the logged on user.
.NOTES
File Name : Get-ComputerDomain.ps1
Author : Thomas Lee - tfl@psp.co.uk
Requires : PowerShell V2 CTP3
.LINK
This script posted to:
http://pshscripts.blogspot.com/2009/01/get-domain.html
MSDN Sample posted at:
http://msdn.microsoft.com/en-us/library/system.directoryservices.activedirectory.domain.getcomputerdomain%28VS.80%29.aspx
.EXAMPLE
PS c:\foo> .\Get-ComputerDomain.ps1
Your computer is a member of the cookham.net domain
Role Holders in this domain:
PDC Role Holder : Cookham1.cookham.net
RID Role Holder : Cookham1.cookham.net
InfraM Role Holder : Cookham1.cookham.net
#>
###
# Start of script
###
# Get Domain information using static method
$domain = [System.DirectoryServices.ActiveDirectory.Domain]::GetComputerDomain()
# Display information for current computer
"Your computer is a member of the {0} domain" -f $domain.name
"Role Holders in this domain:"
" PDC Role Holder : {0}" -f $domain.PdcRoleOwner
" RID Role Holder : {0}" -f $domain.RIDRoleOwner
" InfraM Role Holder : {0}" -f $domain.InfrastructureRoleOwner
# End of script
- 6/1/2010
- Thomas Lee
- 6/1/2010
- Thomas Lee