Link to home
Start Free TrialLog in
Avatar of Lydia626
Lydia626

asked on

Scheduling a powershell script as a sql agent job

I have a script that when I run straight from powershell or as a windows scheduled task works
fine.

The script does a bcp to my logs into a csv file zips it then deletes the zip.  When I run the script as a scheduled job from sql the job says it has completed but the zip is not deleted. When I check the history I see this message.

Executed as user: host\g. 1  Starting copy...    0 rows copied.  Network packet size (bytes): 4096  Clock Time (ms.): total        1  7-Zip  4.60 beta  Copyright (c) 1999-2008 Igor Pavlov  2008-08-19  Scanning    Creating archive O:\LogsTest\log_.zip    Compressing  exceptionlog_1_.csv    Everything is Oklog_1_ was not found in O:\LogsTest\.  Process Exit Code 0.  The step succeeded.

Any idea why this is happening? I know I have some other zip questions out there but this is unrelated.

I am trying to run this from server 2003 / sql server 2005.

I have also tested this on server 2008 / sql 2008 and the script worked perfect.

The way I am calling the script from server 2003 / sql 2005 is like so.

Type Operating system cmd, run as SQL agent service
powershell.exe c:\logtest.ps1

ASKER CERTIFIED SOLUTION
Avatar of TempDBA
TempDBA
Flag of India 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 Lydia626
Lydia626

ASKER

I checked the account has admin. the files are being created but the delete step is being skipped.
Avatar of Brent Challis
On the Server 2003 system, what version of PowerShell is installed?
This ended up being a permissions issue.