I have a Windows 10 PC with an admin account and a regular user account. I want to write a Powershell script to run a program in the regular user account from the admin account. So I would run the script from the Admin account and the UI pops up in the user account. The user account would be logged in at the same time as the admin. I tried using psexec.exe but the UI comes up blank and unresponsive in the user account. Is it possible? If so, how do I do it? Thanks
start-process powershell -Credential $user
Where https://serverfault.com/questions/95431/in-a-powershell-script-how-can-i-check-if-im-running-with-administrator-privil shows how to check if you are admin to confirm this:
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
So I launched Powershell as Administrator, used this to check it is Administrator then after launching the other Powershell process from that one confirmed that one was not in Administrator mode.
That should do what you need.
If you want to avoid the password prompt it is possible to generate a credential object to use in the credential parameter instead. I would suggest checking the options here: https://techcommunity.microsoft.com/t5/office-365/cred-get-credential-without-asking-for-prompts-in-powershell/m-p/483274