none
What is my Domain ?

    Question

  • I would like to return on which domain the computer I'm running my script from is.

    For now I'm using $env:USERDNSDOMAIN, but from time to time it doesn't return anything.

    Do you have another way to query the domain a computer is attached to ?

    Tuesday, March 08, 2011 9:46 PM

Answers

  • Found my answer very quickly

    [System.DirectoryServices.ActiveDirectory.Domain]::GetComputerDomain().Name

    • Proposed as answer by KazunMVP Tuesday, March 08, 2011 9:57 PM
    • Marked as answer by Cyreli Wednesday, March 09, 2011 1:09 AM
    • Unmarked as answer by Cyreli Wednesday, March 09, 2011 1:10 AM
    • Marked as answer by Cyreli Thursday, March 10, 2011 4:54 AM
    Tuesday, March 08, 2011 9:47 PM
  • I would use:

    [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().Name

    Richard Mueller - MVP Directory Services
    Wednesday, March 09, 2011 1:37 AM

All replies

  • Found my answer very quickly

    [System.DirectoryServices.ActiveDirectory.Domain]::GetComputerDomain().Name

    • Proposed as answer by KazunMVP Tuesday, March 08, 2011 9:57 PM
    • Marked as answer by Cyreli Wednesday, March 09, 2011 1:09 AM
    • Unmarked as answer by Cyreli Wednesday, March 09, 2011 1:10 AM
    • Marked as answer by Cyreli Thursday, March 10, 2011 4:54 AM
    Tuesday, March 08, 2011 9:47 PM
  • Get-
    WmiObject Win32_NTDomain | select DomainName
    Wednesday, March 09, 2011 12:45 AM
  • I would use:

    [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().Name

    Richard Mueller - MVP Directory Services
    Wednesday, March 09, 2011 1:37 AM
  • There is a quick and simple way to find out the domain name that you are currently connected:

     

    [ADSI]””

     

    Best Regards

    Dale


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
    Wednesday, March 09, 2011 7:05 AM
    Moderator