0
votes

Assume I am running my machine as mydomain\myuser and I need to run some tools that require auth against someone elses domain. I do the following

runas /user:theirdomain\theiruser /netonly powershell.exe

Then in any powershell commands that I run in that powershell window I need to detect the theirdomain\theiruser that I ran with.

This was discussed here but for .net and there wasn't any solutions.

The implication was that you could run something remoted somewhere and be able to then ask that remote server what user they are using. I don't have any powershell remoting knowledge but lets assume that I have a Powershell running server somewhere that I could run a remote command against - could I use that to capture the NetOnly username?

in the meantime I think I will try to pass the username separately to the environment somehow but there must be a more elegant solution for this?

Thanks for any thoughts!

1
Have you tried running whoami in the remote powershell session? - Rich Moss

1 Answers

0
votes

I recommend using the following:

Invoke-Command -ScriptBlock {Get-Process} -ComputerName $computerName -Credential (Get-Credential)

or you can use the following:

Enter-PSSession -Credential (Get-Credential) -ComputerName $computerName

If you prefer to run individual commands by hand, with those credentials:

Also, keep in mind Get-credential is not the only way to create a PSCredential, refer to Microsoft documentation for more examples.