$env:USERDNSDOMAIN question

Welcome Forums General PowerShell Q&A $env:USERDNSDOMAIN question

This topic contains 3 replies, has 2 voices, and was last updated by

3 years, 3 months ago.

  • Author
  • #33705

    Points: 0
    Rank: Member

    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

    Points: 0
    Rank: Member

    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

    Points: 639
    Helping Hand
    Rank: Major Contributor

    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

    Points: 0
    Rank: Member

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

    I appreciate your input!

The topic ‘$env:USERDNSDOMAIN question’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort