Powershell and a J.O.B

I really dont know how easy or difficult this could be. But I am placing it here just in case.

Regarding question:
http://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
LVL 8
Leo TorresSQL DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DBAduck - Ben MillerPrincipal ConsultantCommented:
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.
0
Leo TorresSQL DeveloperAuthor 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
0
DBAduck - Ben MillerPrincipal ConsultantCommented:
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.
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Leo TorresSQL DeveloperAuthor 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.
0
DBAduck - Ben MillerPrincipal ConsultantCommented:
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?
0
Leo TorresSQL DeveloperAuthor Commented:
Its right here in the link of original post
http://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.
0
DBAduck - Ben MillerPrincipal ConsultantCommented:
Ok, so I see that there is a $ie.visible = $true. You should try it with $ie.visible = $false

I just tested a little and it did not show IE and that will keep things from hanging.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Leo TorresSQL DeveloperAuthor Commented:
I tried sol agent job with visible false. I will try to remove write to host and see.
0
Leo TorresSQL DeveloperAuthor 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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.