$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%3CLINGO-SUB%20id%3D%22lingo-sub-1724019%22%20slang%3D%22en-US%22%3ERe%3A%20%24env%3AUsername%20Different%20Outputs%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1724019%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F784168%22%20target%3D%22_blank%22%3E%40Schulzi%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20is%20normal%20behavior%2C%20as%20PowerShell%20which%20%22Run%20as%20Administrator%22%20will%20start%20in%20the%20system32%20directory%2C%20as%20it%20already%20has%20the%20access%20to%20it%20%22it%20ran%20as%20admin%22%3C%2FP%3E%3CP%3Ebut%20running%20PowerShell%20normally%20will%20make%20PowerShell%20set%20the%20path%20to%20the%20user%20home%20directory%20as%20its%20the%20path%20it%20has%20access%20to%2C%20and%20it%20doesn't%20have%20full%20control%20over%20the%20system32%20folder.%3C%2FP%3E%3CP%3Ethe%20username%20used%20is%20the%20same%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1738956%22%20slang%3D%22en-US%22%3ERe%3A%20%24env%3AUsername%20Different%20Outputs%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1738956%22%20slang%3D%22en-US%22%3E%3CP%3E%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%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThat%20does%20not%20answer%20my%20question...%3C%2FP%3E%3CP%3EMy%20Question%20still%20is%20%22Why%20does%20Powershell%20launch%20in%20different%20Identities%3F%22%3C%2FP%3E%3CP%3EFor%20my%20point%20of%20view%20(and%20the%20one%20of%20my%26nbsp%3Bcolleague)%20it's%20happening%20random%2C%20without%20a%20obvious%20reason...%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWe%20can%20launch%20Powershell%20on%202%20different%20systems%20ON%20THE%20SAME%20WAY%20and%20on%20one%20PC%20it%20launches%20under%20%22User%22%20and%20the%20other%20one%20launches%20under%20%22system32%22.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENothing%20done%20different%2C%20but%20still%20got%20different%20results...%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGreeting%3C%2FP%3E%3CP%3EYannik%20Schulz%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
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

5 Replies

@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

 

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

 

 

 

@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

@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

 

Quick Update what I want to do:

Launching Powershell as an Admin but still stay in the Current User (T4....-User) and not as the Admin User (cat....)

The "T-Users" dont have Admin-privileges the "Cat-Users" have...

BUT in need to stay logged on as the "T-User" in the new PS-Session/Windows that my script will work properly to edit all information in the "T-User-Profile".

 


Greetings
Yannik Schulz