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!
Run a PSscript with other credentials, capture the output/debug as admin?
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.
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.
Re: Run a PSscript with other credentials, capture the output/debug as admin?
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
Start by reading the help carefully until you understand what is telling you.
help about_PowerShell.exe
Re: Run a PSscript with other credentials, capture the output/debug as admin?
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
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
- Alexander Riedel
- Posts: 8489
- Last visit: Thu Apr 18, 2024 9:59 am
- Been upvoted: 37 times
Re: Run a PSscript with other credentials, capture the output/debug as admin?
You'll need to show your actual code, not just the one line.
Show the function or event handler wherein you call that.
Show the function or event handler wherein you call that.
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: Run a PSscript with other credentials, capture the output/debug as admin?
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.(the script runs under admin credentials so a normal user should not have the option to enter stuff in the powershell).
Without some clear idea of what the task is there is really no oi way to advise you.
Re: Run a PSscript with other credentials, capture the output/debug as admin?
Thanks for the input. I had a typo, will get back with details later on to finetune if needed.