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 :
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. Invoke-Command -ComputerName computername - ScriptBlock {Start-Process cmd -ArgumentList '/c cmdcommand > output.txt -Verb runas} -Credentials $cred
. I do not get any output. runas
paramter, 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?
Execute:
Enable-PSRemoting -Force
In an elevated prompt on your target PC. Then Restart-Service WinRM
Enter-PSSession -ComputerName $rpc -Credential (Get-Credential)
If you are able to remote to Default endpoint Microsoft.PoweShell, That means the executing user is an administrator in the destination machine.
But here, I suspect the cmdcommand
you specified is actually doing some execution which targets a remote resource, hence it will become a dual hope issue.
if so, below article will be a solution for you issue.
Its all about Credential Delegation
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.