December 30, 2025 at 10:05 am
I have a couple of SQL Agent job steps which run PowerShell commands of the form:
Invoke-Command -ComputerName REMOTE -ScriptBlock {& "E:\Scripts\PowerShellScript.ps1" -ServerName "REMOTE\INSTANCE"}In each case, these steps have started failing with errors of the form:
The job script encountered the following errors. These errors did not stop the script:
Unhandled Exception: System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)
at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)
at Microsoft.SqlServer.Management.PowerShell.Res.GetString(String key, Object arg0)
at Microsoft.SqlServer.Management.PowerShell.SqlPowerShell.GetErrorRecordMessage(ErrorRecord errorRecord)
at Microsoft.SqlServer.Management.PowerShell.SqlPowerShell.HandleAgentJob(RunspaceConfiguration config, IList`1 listOfScriptConfigurationEntries)
at Microsoft.SqlServer.Management.PowerShell.SqlPowerShell.Main(String[] args)
I've added a "Start-Transcript" to the top of the script but the output file doesn't get created, so I don't think the script is being executed.
If I run "powershell.exe" as the proxy account defined for this job step and run the same command, it runs without issue. So the script is fine and the permissions aren't an issue.
I'm wondering if there's something related to the version of PowerShell used by SQL but can't see why this would be different to a similar setup on another SQL 2019 instance - which works fine.
Viewing post 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply