Get an Active Directory domain.
Syntax Get-ADDomain [-Current {LocalComputer | LoggedOnUser}] [-AuthType {Negotiate | Basic}] [-Credential PSCredential] [-Server string] [CommonParameters] Get-ADDomain [-Identity] ADDomain [-AuthType {Negotiate | Basic}] [-Credential PSCredential] [-Server string] [CommonParameters] Key -AuthType {Negotiate | Basic} The authentication method to use: Negotiate (or 0), Basic (or 1) A Secure Sockets Layer (SSL) connection is required for Basic authentication. -Credential PSCredential The user account credentials to use to perform this task. The default credentials are those of the currently logged on user unless the cmdlet is run from an Active Directory PowerShell provider drive. If the cmdlet is run from such a provider drive, the account associated with the drive is the default. Type a user name, such as "User64" or "Domain64\User64" or specify a PSCredential object such as one generated by Get-Credential If a user name is specified, the cmdlet will prompt for a password. -Current ADCurrentDomainType Whether to return the domain of the local computer or the current logged on user (CLU). Possible values: LocalComputer (or 0), LoggedOnUser (or 1) -Identity ADDomain An AD domain object, provide one of the following values: (The identifier in parentheses is the LDAP display name for the attribute.) Distinguished Name Example: DC=aberdeen,DC=SS64,DC=com GUID (objectGUID) Example: 599c3d2e-f72d-4d20-8a88-030d92495f22 Security Identifier (objectSid) Example: S-1-5-21-3164297888-301567370- DNS domain name Example: aberdeen.SS64.com NetBIOS domain name Example: aberdeen The cmdlet searches the default naming context or partition to find the object. If two or more objects are found, the cmdlet returns a non-terminating error. This parameter can also get this object through the pipeline or you can set this parameter to an object instance. This example shows how to set the parameter to a distinguished name. -Identity "aberdeen.SS64.com" This example shows how to set this parameter to a optional feature object instance named "domainInstance". -Identity $domainInstance -Server string The AD Domain Services instance to connect to, this may be a Fully qualified domain name, NetBIOS name, Fully qualified directory server name (with or without port number) CommonParameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable, -OutBuffer -OutVariable.
Set-ADDomain modifies the properties of an AD domain. Commonly used property values may be set using the cmdlet parameters, other property values can be modified by using the -Add, -Replace, -Clear and -Remove parameters.
The -Identity parameter specifies the domain to modify. Specify a domain by its distinguished name (DN), GUID, security identifier (SID), DNS domain name, or NetBIOS name.
The -Instance parameter provides a way to update a domain object by applying the changes made to a copy of the domain object. When you set the -Instance parameter to a copy of an AD domain object that has been modified, Set-ADDomain can then save the changes to the original domain object. To get a copy of the object to modify, use Get-ADDomain. When you specify the -Instance parameter you should not pass the identity parameter.
The following examples show how to modify the ManagedBy property of a domain object by using three methods:
-By specifying the -Identity and the -ManagedBy parameters
-By passing a domain object through the pipeline and specifying the -ManagedBy parameter
-By specifying the -Instance parameter.
Method 1: Modify the ManagedBy property for the Aberdeen domain by using the -Identity and -ManagedBy parameters.
Set-ADDomain -Identity Aberdeen -ManagedBy JaneJacobs
Method 2: Modify the ManagedBy property for the Aberdeen domain by passing the Aberdeen domain through the pipeline and
specifying the -ManagedBy parameter.
Get-ADDomain Aberdeen | Set-ADDomain -ManagedBy JaneJacobs
Method 3: Modify the ManagedBy property for the Aberdeen domain by using the PowerShell command line to modify a local instance of the Aberdeen domain. Then set the -Instance parameter to the local instance.
$domain = Get-ADDomain Aberdeen
$domain.ManagedBy = JaneJacobs
Set-ADDomain -Instance $domain.
Examples
Get the domain information for the domain SS64.com
PS C:\> Get-ADDomain SS64.com
Get the domain information of the current local computer domain:
PS C:\> Get-ADDomain -Current LocalComputer
Get the domain information for the domain of the currently logged on user:
PS C:\> Get-ADDomain -Current LoggedOnUser
PS C:\> Get-ADDomain
“In order to be an immaculate member of a flock of sheep, one must above all be a sheep oneself” ~ Albert Einstein
Related PowerShell Cmdlets:
Set-adDomain - Modify an AD domain.
Get-adDomainController - Get one or more AD domain controllers, based on name or search criteria.