How to use 'Run As Specified User' credentials in my script further ?

Ask your PowerShell-related questions, including questions on cmdlet development!
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.
This topic is 8 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
ashish44s
Posts: 17
Last visit: Wed May 03, 2017 4:05 pm

How to use 'Run As Specified User' credentials in my script further ?

Post by ashish44s »

Hi All,

Greetings !!!

I'm using PowerShell Studio 2012 to create one tool to perform different administrative tasks. I do not want to run the output tool.exe as an administrator. I want to run that as 'Run As Different User' and provide credentials at that time. Also, I want to use those credentials further in my script to perform several tasks on remote computers without providing them again and again during run-time.

Can you please help to suggest a method to do that ?

Thanks...
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: How to use 'Run As Specified User' credentials in my script further ?

Post by jvierra »

You can't. You can re-launch your script using credentials

$cred=Get-Credential
start-process -FilePath powershell -ArgumentList "c:\temp\myscrip.ps1" -Credential $cred
User avatar
ashish44s
Posts: 17
Last visit: Wed May 03, 2017 4:05 pm

Re: How to use 'Run As Specified User' credentials in my script further ?

Post by ashish44s »

Do you know how and where PowerShell Studio keeps my credentials when I launch EXE with 'Run As Different User' ?
I'm asking because I'm able to do some task written in script with those provided credential as cmdlets don't require them For e.g. Get-Service

But, if I need to run a command to remove app-v package on remote machine, it requires credentials if used with Invoke-Command.

Invoke-Command -ComputerName $c -ScriptBlock {Remove-AppvClientPackage -Name XXX} -Credential $cred


I want to use $cred as what I provided to run my EXE.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: How to use 'Run As Specified User' credentials in my script further ?

Post by jvierra »

$cred is not stored anywhere.

When you use RunAs the credentials are stored in the password vault. Unfortunately it requires elevation to retrieve the password.
This topic is 8 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked