$env:USERDNSDOMAIN question

This topic contains 3 replies, has 2 voices, and was last updated by Profile photo of ertuu85 ertuu85 10 months, 4 weeks ago.

  • Author
    Posts
  • #33705
    Profile photo of ertuu85
    ertuu85
    Participant

    If I understand correctly using $env:USERDNSDOMAIN while not logged in as a domain user will produce no results.

    So if the above statement is true, 2 questions.

    1) Is that for both 2008 and 2012?
    2) Is there a way to pull the same results while not logged in as a domain user?

  • #33706
    Profile photo of ertuu85
    ertuu85
    Participant

    I may have asked a little too soon...I think

    (gwmi win32_ntdomain).dnsforestname

    Should work, but I'm not sure if this is the best way to grab it

  • #33715
    Profile photo of Rob Simmers
    Rob Simmers
    Participant

    Your question needs context to explain what you want and how you are intending on getting it. Environment variables are created per session, so there has to be a (user) session to get environment variable data. If I am logged in and you run a script remotely on my system, $env: is the environment of WHO is running the script, not another user that is logged on to the system.

    You can use WMI to get domain information, but the user's domain and the computer's domain may not be the same. This makes it confusing as to what you are looking for. A more common WMI call would be:

    gwmi win32_ComputerSystem | Select Domain
    
  • #33735
    Profile photo of ertuu85
    ertuu85
    Participant

    Ah thank you Rob, I am looking for the actual domain of the server.

    I appreciate your input!

You must be logged in to reply to this topic.