Question:
I have a simple Powershell script (that’s being run in a step in Octopus deploy) that I’m trying to run as another user. We need it for future steps (each application on our platform runs as its own user account, and I need to be able to run an arbitrary script as that user during the deployment process).
The problem is that even the simplest script fails with completely unhelpful error messages, such as this:
1 2 3 4 5 6 7 8 9 |
$secpasswd = ConvertTo-SecureString $OctopusParameters["runAsPassword"] -AsPlainText -Force $credential = New-Object System.Management.Automation.PSCredential ($OctopusParameters["runAsUsername"] , $secpasswd) $job = Start-Job -scriptblock { whoami } -credential $credential $job | Receive-Job -Wait |
Which fails with the message:
The background process reported an error with the following message: .
The Octopus tentacle is running as a domain account with admin privileges on the machine.
I’ve completely exhausted all avenues of investigation now, but we really need to get this working. I think if we can’t run a deployment script as a certain user then we’re completely screwed.
Answer:
Nearly three years later I have the same issue… I tried writing the code to a temporary file and using Start-Process, but couldn’t get that to work either.
In the end, I wrote the code to file, and then ran it through the Windows task scheduler.