Link to home
Start Free TrialLog in
Avatar of Zack
ZackFlag for Australia

asked on

Powershell Problem

Heyas,

I can't get an particular SQL query to export to txt file.  The powershell script I have works for all other sql queries and what the script does is export the query results to a txt file.I have administrative rights on my server and below is the sql query.
SELECT
		sysjobs.Name
FROM      msdb..sysjobhistory
		INNER JOIN  msdb..sysjobs ON msdb..sysjobs.job_id= msdb..sysjobhistory.job_id

I also have error catch statement on my powershell but it never returns any errors.

But I never any get any results back from the server. Is this a security issue any ideas?



Thank you.
Avatar of Zack
Zack
Flag of Australia image

ASKER

Any ideas anyone?
Avatar of chrismerritt
chrismerritt

Does this work?

USE msdb
SELECT sj.Name
FROM sysjobs As sj
INNER JOIN sysjobhistory As sjh
ON sj.job_id = sjh.job_id

Open in new window


Does the code work if you run it against the DB in SQL Management Studio?
Is it possible one (or both) table(s) are empty?
Avatar of Zack

ASKER

The code works fine SQL Management Studio, just not when I try get the run sql query from the powershell script I created. I have tested the powershell script with other queries I have developed and they work fine.

Thank you.
ASKER CERTIFIED SOLUTION
Avatar of Daniel_PL
Daniel_PL
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Zack

ASKER

My apologies for the delay in answering net connection was down.
No problem, it's goo to know your issue is resolved ;)