$env:Username Different Outputs

Brass 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