PSCredentials not being respected when running DBATools inside PSU script/dashboard

In both dashboard as well as scripts:

  • Script using dbatools
  • PSCredential object called ‘webatch’ saved as a secret
  • Service account called ‘uauto’ running the Universal Automation service
  • Connect to database with -sqlcredentials $webatch
  • Get back a message that i failed to connect at ‘uauto’
  • Both accounts are local admin on the PSU server (not IIS hosted)
  • works in ISE/Powershell

Script being run:
import-module dbatools
Get-Variable Webatch
write-output “Attempting to use $($webatch.username)”
$sqlconnection = Connect-DbaInstance -SqlInstance $SQLInstance -Database $Database -sqlcredential $webatch

Output from Log:
[2:54:38 PM] [INF] webatch System.Management.Automation.PSCredential
[2:54:38 PM] [INF] Attempting to use ‘domain\webatch’
[2:54:40 PM] [ERR] Login failed for user ‘domain\UAuto’.

For Universal Scripts it works when I specify the environment to run in 5.1 (by default its running in 7.0.3)
It doesn’t make a difference for the dashboard

Update - removed powershell 7 from the PSU server. working now