• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

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
0
Leo Torres
Asked:
Leo Torres
  • 5
  • 4
1 Solution
 
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
 
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

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now