Domain.GetCurrentDomain Method
.NET Framework 2.0
Gets the Domain object for the current user credentials in effect for the security context under which the application is running.
Namespace: System.DirectoryServices.ActiveDirectory
Assembly: System.DirectoryServices (in system.directoryservices.dll)
Assembly: System.DirectoryServices (in system.directoryservices.dll)
GetCurrentDomain method is determined by the domain credentials under which the application is running. To retrieve the Domain object representing the domain to which the computer running the application is joined, regardless of the credentials associated with that application, use the GetComputerDomain method instead.
See Also
GetComputerDomain
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 GetCurrentDomain to return information about the domain
.DESCRIPTION
Uses system.directoryservices.activedirectory.domain and GetCurrentDomain
to return domain information of the currently logged on user. NOte that this
may be different to the domain of the computer itself.
.NOTES
File Name : Get-Domain.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.getcurrentdomain%28VS.80%29.aspx
.EXAMPLE
PS c:\foo> .\get-domain.ps1
You are connected to 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
$domain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
# Display information
"You are connected to 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