I won't get into all the details of why I need this, but users must be able to launch PowerShell as a service account and when PowerShell loads it needs to run a script. I already can launch PowerShell with the stored credentials (stored as a secure string), but for the life of me I cannot get the script (located in $args) to run. I have tried a variety of things, and below is where I am currently. Any help would be greatly appreciated.
$user = "domain\service.account" $pwd1 = "big long huge string of characters" $pwd = ($pwd1 | ConvertTo-SecureString) $Credential = New-Object System.Management.Automation.PSCredential $user, $pwd $args = "\\domain.local\location\location\location\Script\script.ps1" Start-Process powershell.exe -Credential $Credential -ArgumentList ("-file $args")
In File Explorer (or Windows Explorer), right-click the script file name and then select "Run with PowerShell". The "Run with PowerShell" feature starts a PowerShell session that has an execution policy of Bypass, runs the script, and closes the session.
When you start a PowerShell script, do it as here: Run PowerShell (or ps.exe) and add the script file with -file <script. ps1> as argument. Then, add the desired credentials by clicking the Change User or Group button.
Open the task manager by using the shortcut keys Ctrl+Alt+Del. Explore the File tab and Run a new task by clicking on the option given. In the PowerShell type the same command start-process PowerShell -verb runas and hit enter to run it as administrator.
You can open a new powershell window under a specified user credential like this:
start powershell -credential ""
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With