Trigger a sqlagent job form Powershell

I am trying to trigger a sql agent job from a powershell script and I want to add powershell script and add it to  task scheduler. Here is where I am stuck.All I am trying to do is check if a new file exists at a specified location. if yes then execute a sql agent job else let me know file not exists

Import-Csv .\*.csv | ForEach { If (Test-Path -Path $_.File) {

--how do I trigger the sqlagent job } Else { Write-Output "No CSV file does NOT exist" } }

August 31st, 2015 4:48pm

You would do better to use SSIS scheduled via a script.  What you are trying too do does not make much sense in MSSQLServer. Why use PowerShell when you have an d agent and a built in script agent.

Other options would be to use a stored procedure.

Free Windows Admin Tool Kit Click here and download it now
August 31st, 2015 6:06pm

exec sp_start_job

https://msdn.microsoft.com/en-us/library/ms186757.aspx?f=255&MSPPError=-2147217396

August 31st, 2015 6:08pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics