I have code that is being invoked by a third party program. Unfortunately, it does not allow for the use of elevated credentials to run this script.
I was told the best approach is to have the third party program invoke a program that uses Start-Process, which in turn will invoke the script that requires the elevated credentials.
For simplicity, I am attempting to use Start-Process to run a program that outputs "Hello World", and I cannot figure out why it is unable to work
#hello.ps1
Write-Host Hello World
And here is the code that uses stored, encrypted password to create credentials to use in Start-Process
#start.ps1
<#Previously created password file in C:\Script\cred.txt, read-host -assecurestring | convertfrom-securestring | out-file C:\Script\cred.txt#>
$password = get-content C:\Script\cred.txt | convertto-securestring $credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist "DOMAIN\Username",$password $script = "C:\script\hello.ps1" Start-Process -FilePath 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe' -Credential $credentials -ArgumentList "-file $script"
Instead of the "Hello World" being output on the Powershell_ise GUI, the cmd window pops up, and no output is written
1. How to make "Hello World" print to the Powershell_ise GUI
2. How to suppress the cmd window from popping up?
EDIT
Ok, I updated my code by changing parameters of start-process
start-process powershell -Credential $credentials -ArgumentList '-noexit','-File','C:\script\hello.ps1'
but I still have two issues
1. I am using Powershell_ise.exe. How to make "Hello World" print to the GUI
2. How to suppress the cmd window?