I am very inexperienced with Windows PowerShell but this should be a simple question for those in the know.
I use a Windows 11 computer at my new place of employment. I wanted to know what Windows domain my user account was a part of. I know which domain my computer is a member of, but my user account may be a member of another domain. So, I performed a Google search and found a way using the Windows Command Prompt. I was instructed to type “echo %userdomain%”. I decided to type this command in Windows PowerShell instead, since I know that many commands work in both Command Prompt and PowerShell. PowerShell, however, simply produced “%userdomain%” after I typed the command and pressed “enter” on the keyboard. I then typed “echo %username%”, pressed “enter”, and the result shown was simply “%username%”. I then typed these commands in Windows Command Prompt and found the information that I wanted. So, the commands obviously work differently in the 2 applications.
I am a bit concerned, however, with the commands that I entered in PowerShell since I have no idea what might result from this command. Did I change a setting that I should not have? Did I damage my computer? Will my computer grow wings and fly away? Any help that you fellows could give to ease my mind would be greatly appreciated!
So in short, in a Shell terminal, %userdomain% is a set provided variable that’s already created within the environment. In PowerShell, %userdomain% has to be configured. Here’s a good link about using environment variables in PS.
However, if you wanted to try using the preconfigured environment variable, you would have to do $Env:<variable-name> assuming that the variable exists as described in the link above.
To add to Austin’s post, the exact translation from Command Shell to Powershell would be:
$ENV:UserDomain
I have found that PowerShell maps all the system variables in $ENV. From your command shell, simply enter “set” to view what is defined. Then you can translate view/use those in PowerShell by simply prefixing them with …
Simply typing the commands will only reveal their values. Changing the values in a script will only be relevant to that instance of Powershell, not the entire system. If you refer back to Austin’s link, it will show you how to actually change them at the system level.
I can close a Windows Command Prompt window by simply typing “exit” and then pressing the “enter” key on my keyboard. Is this the proper way to close PowerShell?
Is the window, in PowerShell, actually called a “Shell terminal”?