Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

powershell script through agent job only performing half the steps it should. Expand / Collapse
Author
Message
Posted Friday, August 16, 2013 2:07 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Today @ 8:32 AM
Points: 48, Visits: 426
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?
Post #1485371
Posted Friday, August 16, 2013 3:05 PM


Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Yesterday @ 6:45 AM
Points: 60, Visits: 880
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.
Post #1485383
Posted Monday, August 19, 2013 12:58 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: 2 days ago @ 12:24 PM
Points: 157, Visits: 935
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
Post #1485958
Posted Monday, August 19, 2013 1:44 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Today @ 8:32 AM
Points: 48, Visits: 426
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.
Post #1485981
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse