|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 5:46 AM
Points: 257,
Visits: 671
|
|
So at this point your job is completing and successfully loads the data and archives the csv files, but it does not include job step output information in the job history?
If this is the case the reason why the step output does not include job step output information for the second step is due to the implementation of some very basic threading (I'm not sure I should even call it threading). In run-SmoToCsvFile.ps1 there is a function called "LaunchThread" which uses the .NET System.Diagnostics.ProcessStartInfo to start several new independent powershell consoles running Write-SmoToCsvFile.ps1 (the number depends on your $maxthread setting). The problem with this approach is the original Powershell command executed from SQL Agent has no knowledge of the independent shells. It just starts them, kind of like sp_start_job in SQL Server. If you execute sp_start_job you only receive success or failure of the job starting and not whether the job itself completed or failed.
This causes some little problems. First as you pointed out the original session does not get back information which would ultimately show up in the job step. This is also why Write-SmoCsvToDb which does not launch additional powershell consoles returns job step output information. The second problem is that Write-SmoCsvToDb can start prior to all the independent powershell consoles running Write-SmoToCsvFile completes. To overcome the second problem I had to include a WAIT step in the job after Run-SmoToCsvFile:
WAITFOR DELAY '00:30' For the first problem I've tried to include output files rather than use the job step output.
Admittedly the solution of launching multiple Write-SmoToCsvFile.ps1 scripts from Run-SmoToCsvFile.ps1 is less than ideal. On the plus side I'm able to reduce total runtime significantly by launching multiple processes instead of processing through each server sequentially.
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: 2 days ago @ 12:53 PM
Points: 273,
Visits: 451
|
|
Unfortunately not, the job just generates the log files. There are no csv files created or archived. apparently the first PS script doesnt begin, just the SS job log files are created...
I am wondering whether to create a .bat or .vbs file that will run the PS scripts and then start that off from the SS job ("the knee bone is connected to the ankle bone, the ankle bone is connected to the .... !!!")
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 5:46 AM
Points: 257,
Visits: 671
|
|
This might seem obvious but your execution policy is set to remotesigned? Also you may want to just run Write-SmoToCsvFile.ps1 and pass in the server name instead of using Run-SmoToCsvFile.ps1 as a test:
C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.EXE -command "C:\SQLPSX\Write-SmoToCsvFile.ps1 'MyServer'"
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: 2 days ago @ 12:53 PM
Points: 273,
Visits: 451
|
|
Yes - remotesigned.
Tried the single server name in threee styles - - SERVER\INSTANCE - SERVER - INSTANCE
and there is no difference in the execution. A log files gets created and archived.
no other work done.
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Wednesday, April 04, 2012 10:02 PM
Points: 11,
Visits: 231
|
|
| I am getting the same problem as Jonathan, is there a workaround for this when using the agent to run the job?
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 5:46 AM
Points: 257,
Visits: 671
|
|
I have dozens SQL Agent jobs in 2000 and 2005 servers which call powerhell scripts from powershell.exe. The JobStep type is set to CmdExec. Try testing a single job step: C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.EXE -command "C:\SQLPSX\Write-SmoToCsvFile.ps1 'MyServer\InstanceName'" Ensure you have all of the .ps1 files in the same directory and they all been unblocked and of course your execution policy is set to remote signed. Whenever I've had trouble running powershell.exe from SQL Agent it has been either an execution policy or script path issue.
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Wednesday, April 04, 2012 10:02 PM
Points: 11,
Visits: 231
|
|
Thank you for your reply cmille19, the job works fine for generating the csvs but after running run-smo step im getting this: The step did not generate any output. Process Exit Code 0. The step succeeded. (i.e. I am getting this error when running the single job step) The logs are also fine and the jobstep type is set to cmdexec (execution policy is set to remotesigned)
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 5:46 AM
Points: 257,
Visits: 671
|
|
valenzat (12/8/2008) Thank you for your reply cmille19, the job works fine for generating the csvs but after running run-smo step im getting this: The step did not generate any output. Process Exit Code 0. The step succeeded. (i.e. I am getting this error when running the single job step) The logs are also fine and the jobstep type is set to cmdexec (execution policy is set to remotesigned)
Are you able to run successfully manually outside of SQL Agent?
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Wednesday, April 04, 2012 10:02 PM
Points: 11,
Visits: 231
|
|
yes it works if im not using the agent. I also tried using xp_cmdshell with T-sql step but no luck Im getting the csv files but nothing gets inserted to the db..am i missing something with using the agent?is there a way to troubleshoot that?
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 5:46 AM
Points: 257,
Visits: 671
|
|
Are CSV files on the local SQL Server? Is the SQL Agent running under Local System or a Windows account?
|
|
|
|