您需要创建一个凭据、一个SQL 代理代理,然后将代理帐户分配给 SQL 代理作业步骤。代理帐户特定于每个子系统(例如 Powershell、CmdExec、SSIS 等)
-- creating credential
USE [master]
GO
CREATE CREDENTIAL [Superuser] WITH IDENTITY = N'DOMAIN\account', SECRET = N'mypassword'
GO
-- creating proxy for CmdExec subsystem, adding principal
USE [msdb]
GO
EXEC msdb.dbo.sp_add_proxy @proxy_name=N'My custom proxy',@credential_name=N'Superuser',
@enabled=1
GO
EXEC msdb.dbo.sp_grant_proxy_to_subsystem @proxy_name=N'My custom proxy', @subsystem_id=3
GO
EXEC msdb.dbo.sp_grant_login_to_proxy @proxy_name=N'My custom proxy', @fixed_server_role=N'sysadmin'
GO
-- assigning job step to run as a given proxy user
USE [msdb]
GO
EXEC msdb.dbo.sp_update_jobstep @job_id=N'0df2dac2-4754-46cd-b0bf-05ef65e1f87e', @step_id=1 , @subsystem=N'CmdExec',
@proxy_name=N'My custom proxy'
GO