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.
- Is that for both 2008 and 2012?
- Is there a way to pull the same results while not logged in as a domain user?
I may have asked a little too soon…I think
Should work, but I’m not sure if this is the best way to grab it
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
Ah thank you Rob, I am looking for the actual domain of the server.
I appreciate your input!