powershell script through agent job only performing half the steps it should.

  • Ok. I'm out of ideas.

    I have a script that grabs a list of sqlserver instances, then connects to each (foreach), executes a query and loads the results into a table.

    Every time I execute the script through a sql agent job(via cmdexec) , it only queries against 2 of the 4 servers it should.

    Its run successfully from powershell, powershell ise, starting powershell through sql server, it even runs successfully if I run it through a standard command prompt.

    Any ideas?

  • Any errors or does it just exit? Are you doing any logging that might help point to the issue?

    I do something similar but have one server that would throw a connection error. I had to monkey the connection string for it before my script would run to completion.

  • I do something similiar, with a couple of differences. One, I run the step as type PowerShell. The other thing I do, and I suspect this may be your problem, I have a proxy login, that has access to the other servers. Then I change the Run as option to the proxy. Otherwise, the SQL job will run, using the SQL Server agent service account. I do use Windows Authentication, so if you are using SQL login, in your Powershell script, then you should be ok. Since you said you are using cmdexec, i assume you are running a bat file, or executing the powershell exe?

    Leonard

  • So this system is a vast modular monitoring system. The odd thing is that many of the other modules work totally fine. I added some logging to this particular module. Its so odd. The query being executed returns 0 results when run through sql agent. Only for this module.

    Eh, I gave up. I scheduled it using windows scheduler and its working fine.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply