SQL Server Agent with CmdExec job runs PowerShell infinitely
Just ran into this issue and solved it by using powershell -ExecutionPolicy Bypass -File C:\path\to\script.ps1. Seems there was an issue with the signed module so I just set it to not check the sign.
If SQL Server Agent is launching PowerShell via a CmdExec step and appears to run forever, it can also be hanging on interactive prompts (profiles, first‑run messages, etc.). Using a more explicit, non‑interactive call helps:
powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -File C:\path\to\script.ps1
Or if you're on PowerShell 7+:
pwsh.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -File C:\path\to\script.ps1
Note: -ExecutionPolicy Bypass on the PowerShell host only affects that process instance (which is usually what you want for Agent). Keep your script signing policy as strict as you need elsewhere.