I am trying to use a SQL agent job to trigger start another job on another SQL server.
Currently have some on-prem servers and some VM's with SQL Server in Azure. This powershell command is working as expected between the on-prem servers but when executing on an on-prem server to trigger an agent job on one of the azure servers, it doesn't trigger the job. Instead it 'Quits with Success' with the following output:
Message
Executed as user: DOMAIN\sysadminuser. The step did not generate any output. Process Exit Code 0. The step succeeded.
Command:
$ServerName="SQL_On_AzureVM_ServerName"
$JobName="Test"
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null
$srv = New-Object Microsoft.SqlServer.Management.SMO.Server("$ServerName")
$job = $srv.jobserver.jobs["$JobName"]
if ($job)
{
$job.Start()
$i = 0
}