Run a PSscript with other credentials, capture the output/debug as admin?

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
stevens
Posts: 416
Meble kuchenne na zamówienie - na wymiar - Wrocław
Joined: Wed Jun 15, 2016 2:26 am

Run a PSscript with other credentials, capture the output/debug as admin?

Post by stevens »

Hi,

I have a powershell script that I run from a share and which is ran by another user.
It run
Start-Process powershell.exe -ArgumentList -NoProfile -WindowStyle Normal -executionpolicy bypass -noninteractive \\pathtomyscript\script -optionsofscript -credential AdminCredentials

That works fine.
However the powershell window opens then closes, success or failure.

I'd like to keep the Powershell window open when an issue occurs (or even if not) so I can debug but for a normal user it should also show some output "ok or not ok" maybe also the error would be nice (the script runs under admin credentials so a normal user should not have the option to enter stuff in the powershell).

How can I achieve this?
Please advise.
Thanks!

jvierra
Posts: 14368
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Run a PSscript with other credentials, capture the output/debug as admin?

Post by jvierra »

Your arguments are out of order. YOU cannot use named arguments on a command line. THe arguments must be last on the commandline.

Start by reading the help carefully until you understand what is telling you.

help about_PowerShell.exe

User avatar
stevens
Posts: 416
Joined: Wed Jun 15, 2016 2:26 am

Re: Run a PSscript with other credentials, capture the output/debug as admin?

Post by stevens »

Thanks, I will certainly look at it.
But my command is working as is, so would first like to make it work in the GUI, then adapt/finetune.
It works outside the GUI, but within the GUI I get this as a result :-(

>> Start-Process powershell.exe -ArgumentList "$ToExecute" -Credential $AdminCredentials -PassThru -Wait

Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName
------- ------ ----- ----- ------ -- -- -----------
0 0 0 0,52 4984

User avatar
Alexander Riedel
Posts: 7344
Joined: Tue May 29, 2007 4:43 pm

Re: Run a PSscript with other credentials, capture the output/debug as admin?

Post by Alexander Riedel »

You'll need to show your actual code, not just the one line.
Show the function or event handler wherein you call that.
Alexander Riedel
SAPIEN Technologies, Inc.

jvierra
Posts: 14368
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Run a PSscript with other credentials, capture the output/debug as admin?

Post by jvierra »

(the script runs under admin credentials so a normal user should not have the option to enter stuff in the powershell).
If the PS remains running then there is really no way to prevent a user from typing into it an changing anything an admin can change.

Without some clear idea of what the task is there is really no oi way to advise you.

User avatar
stevens
Posts: 416
Joined: Wed Jun 15, 2016 2:26 am

Re: Run a PSscript with other credentials, capture the output/debug as admin?

Post by stevens »

Thanks for the input. I had a typo, will get back with details later on to finetune if needed.

Locked