My scenario : Login to the remote machine via remote desktop connection and open command prompt as admin and execute some admin commands in the command prompt.
I am trying to automate the above scenario through powershell from my local machine.
Below are the steps that I have done :
- To check the working of my powershell script, I manually logged into the remote machine (Admin Cred) and executed this command
Start-Process cmd -ArgumentList '/c cmdcommand > output.txt -Verb runas. This is working as expected in the remote machine as I am getting the desired output. - Now, I tried to execute this command from the local powershell script through
Invoke-Command -ComputerName computername - ScriptBlock {Start-Process cmd -ArgumentList '/c cmdcommand > output.txt -Verb runas} -Credentials $cred. I do not get any output. - But, when I do try to execute the above command without
runasparamter, I get the output saying this particular command needs admin credentials which is expected.Invoke-Command -ComputerName computername - ScriptBlock {Start-Process cmd -ArgumentList '/c cmdcommand > output.txt} -Credentials $cred.
Am I missing something here?