Im trying to run a script as an administrator with the administrator username and password within the script. I know this isnt best practice but Im working on a project where this is a one time use. Ive tried so many way to do this to no avail. Invoke-Command Start-Process Disabled UAC
Asked
Active
Viewed 684 times
0
-
Does this answer your question? [How to run Start-Process in Powershell using user credentials?](https://stackoverflow.com/questions/21758651/how-to-run-start-process-in-powershell-using-user-credentials) – iRon Mar 13 '20 at 07:57
-
No. I tried the code from that page (see below) but get an error. ``` $username = "user" $password = "pass" $credentials = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,(ConvertTo-SecureString -String $password -AsPlainText -Force)) Start-Process powershell.exe -WorkingDirectory C:\testScript.ps1 -Credential ($credentials) – druffin Mar 13 '20 at 14:46
-
Please add what you tried to the question with the exact error message and at which command it occurred. See also: [How to Ask](https://stackoverflow.com/help/how-to-ask) – iRon Mar 13 '20 at 14:54
-
Do not use brackets around variables as: `$credentials`. – iRon Mar 13 '20 at 14:56