$env:Username Different Outputs

%3CLINGO-SUB%20id%3D%22lingo-sub-1719055%22%20slang%3D%22en-US%22%3E%24env%3AUsername%20Different%20Outputs%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1719055%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20a%20little%20Question%2FProblem%20using%20Powershell...%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20got%202%20Different%20PC%20running%20Windows-Powershell%20as%20Admin%20(both%20with%20same%20Domain-Account%20(example%3A%20cat40050))%3C%2FP%3E%3CP%3EBUT%20i%20get%202%20Different%20Outputs...%3C%2FP%3E%3CP%3EOn%20PC1%20I%20get%20the%20current%20User%20that%20is%20logged%20on%20the%20System(example%3A%20T40050)%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Schulzi_1-1601283241106.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F222516i37CF6F5EC8ECDF18%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22Schulzi_1-1601283241106.png%22%20alt%3D%22Schulzi_1-1601283241106.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EOn%20PC2%20I%20get%20the%20Admin%20shown%20that%20is%20running%20Windows-PS...(example%3A%20cat40050)%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Schulzi_0-1601283195594.png%22%20style%3D%22width%3A%20333px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F222515i4995B440E7F6E9EE%2Fimage-dimensions%2F333x63%3Fv%3D1.0%22%20width%3D%22333%22%20height%3D%2263%22%20title%3D%22Schulzi_0-1601283195594.png%22%20alt%3D%22Schulzi_0-1601283195594.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EWhy%20is%20it%20like%20that%3F%3CBR%20%2F%3E%3CBR%20%2F%3EAnd%20is%20there%20a%20way%20to%20say%20%22only%20use%20current%20logged%20on%20user%22%3F%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3ET4....%20Users%20are%20normal%20Users%20with%20no%20Adminprivileges%3C%2FP%3E%3CP%3Ecat4...%20Users%20are%20our%20local%20Admins%20(via%20Domain)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGreetings%26nbsp%3B%3C%2FP%3E%3CP%3EYannik%20Schulz%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1719055%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1723619%22%20slang%3D%22en-US%22%3ERe%3A%20%24env%3AUsername%20Different%20Outputs%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1723619%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F790105%22%20target%3D%22_blank%22%3E%40farismalaeb%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20just%20noticed%20that%20myself...%3C%2FP%3E%3CP%3EI%20startet%202%20Windows%20of%20PS%20now!%3C%2FP%3E%3CP%3E1.%26nbsp%3B%26nbsp%3Bstartet%20via%20%22WIn%2BR%20-%26gt%3B%20pwsh%20-%26gt%3B%20CTRL%2BSHIFT%2BReturn(Starts%20it%20as%20admin)%22%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Schulzi_0-1601374646081.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F222767i4454BDA2703717F3%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22Schulzi_0-1601374646081.png%22%20alt%3D%22Schulzi_0-1601374646081.png%22%20%2F%3E%3C%2FSPAN%3E%26nbsp%3B(cat%20is%20our%20local%20Domain%20Admin)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E2.%20startet%20via%20Startmenu%20(Powershell%20-%26gt%3B%20Run%20as%20Administrator)%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Schulzi_1-1601374698415.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F222768i1BC5BD85B8AE64EC%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22Schulzi_1-1601374698415.png%22%20alt%3D%22Schulzi_1-1601374698415.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EStartet%20in%20%22System32%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20why%20does%20Powershell%20start%20with%20different%20c%3CSPAN%3Eredentials%3F%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EAnd%20how%20can%20I%20%22say%22%20which%20credential%20to%20choose%3F%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EGreetings%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EYannik%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Contributor

Hello,

 

I have a little Question/Problem using Powershell...

 

I got 2 Different PC running Windows-Powershell as Admin (both with same Domain-Account (example: cat40050))

BUT i get 2 Different Outputs...

On PC1 I get the current User that is logged on the System(example: T40050)

Schulzi_1-1601283241106.png

On PC2 I get the Admin shown that is running Windows-PS...(example: cat40050)

Schulzi_0-1601283195594.png

I noticed that one PS-Window is running as "user" and one in "system32"

Both startet from "C:\Windows\System32\WindowsPowerShell\v1.0\"

Why is it like that?

And is there a way to say "only use current logged on user" or start in/as C:\Users\T40...?

T4.... Users are normal Users with no Adminprivileges

cat4... Users are our local Admins (via Domain)

 

 

Greetings 

Yannik Schulz

4 Replies
Highlighted

@Schulzi 

Hi

$Env:Username is a dynamic variable set when the user login, you can also check the value for this variable from CMD by typing %Username%

What might come to my mind is there is an impersonation when, such as a process runas, or Powershell executed under another credential

 

Highlighted

Hi @farismalaeb

 

I just noticed that myself...

I startet 2 Windows of PS now!

1.  startet via "WIn+R -> pwsh -> CTRL+SHIFT+Return(Starts it as admin)"

Schulzi_0-1601374646081.png (cat is our local Domain Admin)

 

2. startet via Startmenu (Powershell -> Run as Administrator)

Schulzi_1-1601374698415.png

Startet in "System32"

 

 

So why does Powershell start with different credentials?

And how can I "say" which credential to choose?

 

Greetings

Yannik

 

 

 

Highlighted

@Schulzi 

This is normal behavior, as PowerShell which "Run as Administrator" will start in the system32 directory, as it already has the access to it "it ran as admin"

but running PowerShell normally will make PowerShell set the path to the user home directory as its the path it has access to, and it doesn't have full control over the system32 folder.

the username used is the same

Highlighted

@farismalaeb 

 

That does not answer my question...

My Question still is "Why does Powershell launch in different Identities?"

For my point of view (and the one of my colleague) it's happening random, without a obvious reason...

 

We can launch Powershell on 2 different systems ON THE SAME WAY and on one PC it launches under "User" and the other one launches under "system32".

 

Nothing done different, but still got different results...

 

Greeting

Yannik Schulz