Hi...
I am trying to create a remote powershell session from which I have to run a PS script which resides on the target server. I need to run this target script with a different user other than which is used to create the remote session. At the end of script I am getting access denied error when the "Start-Process " part executes. I would like to understand what's going wrong with this script.
#############################
$remoteSession=New-PSSession $deplServer -credential $credential1
Invoke-Command -session $remoteSession -scriptblock {
$newcredential = New-Object System.Management.Automation.PsCredential("domain\myuser", (ConvertTo-SecureString "password" -AsPlainText -Force))
Start-Process powershell.exe -Credential $credential2 -ArgumentList "Start-Process powershell.exe -Verb runAs"
}
#############################
And the error:
This command cannot be executed due to the error: Access is denied.
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOp
erationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.C
ommands.StartProcessCommand
#############################