I am trying to use the suggested DbUp solution to deploy some database scripts but I need the DbUp exe to run as a different user. For corporate reasons I cannot give the tentacle permissions to write to a production database so I have to do some impersonation in script.
Below is the PowerShell script I am trying to run. I can successfully run it when I log onto the tentacle machine, open a PS console as my tentancle user account, and run it by typing in “.\Octopus.Action.CustomScripts.Deploy.ps1”. However when I let Octopus run it as a Deploy script I am returned: Script ‘E:\Octopus\Applications\QA\Database\16.3.74525-test\Octopus.Action.CustomScripts.Deploy.ps1’ returned non-zero exit code: -1073741502
Is there are a reason that Start-Process would work when run manually as the tentacle user on the tentacle machine but not when run from by the tentacle? I have tried gutting this script down to bare bones by removing things like the '-RedirectStandardOutput ’ with no luck. The tentacle is version 3.3.12.
Thank you,
Kevin
$user = $OctopusParameters['Administrator AD Account']
$password = $OctopusParameters['Administrator AD Password']
$securePassword = ConvertTo-SecureString -String $password -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, $securePassword
$exe = $OctopusParameters['Octopus.Action[Database Scripts].Output.Package.InstallationDirectoryPath'] + '\AJG.BSD.Pate.Database.exe'
$process = Start-Process $exe -Credential $credential -Wait -NoNewWindow -PassThru -LoadUserProfile -RedirectStandardOutput $env:windir\temp\databaseupdatestandard.log
$process.WaitForExit()
Get-Content -Path $env:windir\temp\databaseupdatestandard.log
exit $process.ExitCode