We help IT Professionals succeed at work.

Powershell and a J.O.B

231 Views
Last Modified: 2014-08-29
I really dont know how easy or difficult this could be. But I am placing it here just in case.

Regarding question:
https://www.experts-exchange.com/Programming/Languages/Scripting/Powershell/Q_28499027.html

The solution provided work like a charm. No issues.


However when I try to run it as a SQL Agent job as an SSIS package or just Plain Powershell code. I runs and it failed. This is most likely because SQL will not allow Powershell to open an Instance of IE and runtime to do test.

So basically what I want to do is place this code on a schedule so it runs every Sunday Morning.

I did try a Windows Task by the way but it just ran and did not produce anything it just hung. So my question is how do I create a Job that runs for the Powerhsell code?

My environment
PS version 4.0
OS Windows 2008 R2
SQL 2008 R2
Comment
Watch Question

DBAduck - Ben MillerSQL Server Architect
CERTIFIED EXPERT

Commented:
Anything that runs in a SQLAgent job should not have a gui that pops up in any case as it may cause the job to fail or SQLAgent to hang.
Leo TorresSQL Developer
CERTIFIED EXPERT

Author

Commented:
Yes, That is correct. Job Fails on SQL Agent and hangs as a Windows Task.

So my Question is what mechanism do I use to run this as a job is my question
DBAduck - Ben MillerSQL Server Architect
CERTIFIED EXPERT

Commented:
In the link above, the code has a Write-Host command, remove that.
Also at the end of it there is an Invoke-Expression that opens the .HTML file and that is probably what hangs things.

Remove those and try it out.
Leo TorresSQL Developer
CERTIFIED EXPERT

Author

Commented:
OK, I will try but I think that should be least of my worries.  The script open IE to navigate thru several hundred pages to test links. I would think that a bigger issue.  The write host I can remove no issue but the IE session may be issue. I will try this afternoon dont have access to code now.
DBAduck - Ben MillerSQL Server Architect
CERTIFIED EXPERT

Commented:
I did not see the code for Test-ReportSite as that may have some issues but I cannot tell.  Everything else in the script I see will work without output to the screen. Can you post the Test-Reportsite code?
Leo TorresSQL Developer
CERTIFIED EXPERT

Author

Commented:
Its right here in the link of original post
https://www.experts-exchange.com/Programming/Languages/Scripting/Powershell/Q_28499027.html#a40266639

Its the second box of code. This opens IE and browses through pages.
SQL Server Architect
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Leo TorresSQL Developer
CERTIFIED EXPERT

Author

Commented:
I tried sol agent job with visible false. I will try to remove write to host and see.
Leo TorresSQL Developer
CERTIFIED EXPERT

Author

Commented:
Not bad answer but not the solution. I turned the script into an executable and ran Executable as job. Give you B for Effort
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.