Let's say I am logged into a server using "user1". I have a project where the powershell process runs under "user2". So every time I execute a script it will be under "user2". Is there a way to specify powershell to run a certain script under "user1" without prompting for credentials (like mentioned before I'm already logged in as that user)? Thanks in advance!
-
1I'm confused. If you are logged onto a server as User1 and you just run a script, it will run as you (User1).EBGreen– EBGreen2018-05-16 12:35:55 +00:00Commented May 16, 2018 at 12:35
-
I run a bat file which opens the powershell process under "user2" . So every other script ran from within the main script will be under "user2".Peta Eduard– Peta Eduard2018-05-16 12:52:11 +00:00Commented May 16, 2018 at 12:52
-
Well then don't run that bat file? Just run the scripts. Or make a differnt bat file that does not run those scripts as the other user.EBGreen– EBGreen2018-05-16 12:58:55 +00:00Commented May 16, 2018 at 12:58
-
1If I didn't want to run the bat file I wouldn't have asked in the first place. I just wanted to know if there is a method to capture the user with which I'm logged in on the server and run certain scripts using that. @xxxvodnikxxx I would prefer a solution without harcoding passwords or prompting me for credentials. I'm more into somehow capturing the user which I'm logged as and run scripts using those credentialsPeta Eduard– Peta Eduard2018-05-16 13:07:37 +00:00Commented May 16, 2018 at 13:07
-
1Unless you tell it otherwise, every script that you run runs as the user that you are logged on as. Period. So, if you can create an example of what you have now then we can tell you how you might accomplish your goal. Otherwise, the question is just not clear enough.EBGreen– EBGreen2018-05-16 13:17:24 +00:00Commented May 16, 2018 at 13:17
1 Answer
No, there is not a way to do this.
The process is running under the context of user2, it cannot run anything in the context of user1 without giving it user1 credentials. As you may be able to imagine if there were a way to do that, it would be a pretty significant security vulnerability.
Bonus Information
If however, you are looking to do something like open a web page as user1 from a process running as user2, you can do so by passing the http/https protocol to the user session IIRC. However, this is only if the process running as user2 is running in the user1 session.
For example:
- Logged in to a console session as User1
- Powershell Process running under User2 context, within the User1 session
- Within the Powershell process, run
start-process http://www.google.com - Default http application opens the URL in the User1 session