I am running a powershell script remotely via an agent. The agent on the machine runs the powershell script as "NT Authority/SYSTEM" but I want to the switch to another user on the system and run the powershell script.
Below is the code that I used to switch to "Administrator" account but I am getting permission denied error .
$username = "domainname\administrator"
$pw = "XXXXXXXX"
$password = $pw | ConvertTo-SecureString -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList $username,$password
Start-Process Powershell.exe -Credential $cred -ArgumentList '-noexit','-File', ' C:\Users\Administrator\test.ps1'
Below is the error I am getting.
Start-Process : This command cannot be run due to the error: Access is denied.