Forum Discussion
GlynLamb
Aug 18, 2021Copper Contributor
Script works in powershell and command line but fails from SQLAgent job step
I have a script using DBAtools cmd Get-DbaDatabase -sqlInstance $Inst which converts to dbaDataTable and writes to a SQL ServerInstance. If I run the script from Powershell ISE works without issue I...
shakyknees
Jan 12, 2022Copper Contributor
GlynLamb I have been working through a somewhat similar problem. To debug it, I setup a test version of the script that uses a different (new) output table using Write-DbaDbTableData -AutoCreateTable, then compare the resulting new table schema to what is expected. That helped me. But as to differences in Powershell behavior between command line vs SQLAgent, my only experience is that I can't use the "Powershell" jobstep defined by SQLAgent, rather must use "Operating System (CmdExec)" to control the Powershell version in use. Which you are probably already doing.
- GlynLambJan 13, 2022Copper Contributor
shakyknees Thanks for your response