Chrissy LeMaire shows how to run Powershell cmdlets from SQL Agent:
By default, only members of the sysadmin role are allowed to create jobs with the CmdExec Job Step, but adding non-sysadmins as principals to the CmdExec proxy works as well.
So here are the steps that I use to schedule my tasks:
-
Create a Windows-based Login in SQL Server
-
Ensure dbatools is available to the account
-
Create a SQL Server Credential
-
Create the Agent Proxy
-
Create the PowerShell .ps1 file
-
Create the Job and Job Step
Chrissy walks you through step by step, making the whole thing easy.