I have a PowerShell script. The way I usually execute this script in the PS console is by using:
. .\psScript.ps1
functionName
functionName is my entry function. I am attempting to run this PowerShell script and auto execute the function functionName as Administrator from a batch file. I can execute this script and function from my batch file using:
powershell -command "& { . .\psScript.ps1; functionName }"
However, this does not execute the script as administrator. So I have also tried the following:
powershell -NoProfile -ExecutionPolicy ByPass -command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy ByPass -File "". .\psScript.ps1; functionName""' -Verb RunAs}"
This still does not work, and the console disappears too quickly for me to read the error message. Could anybody please help?