Link to home
Start Free TrialLog in
Avatar of Lydia626
Lydia626

asked on

Powershell script from SQL Server 2008 not working

I have finished a powershell script that runs perfect, but when I try to run it from a SQL server agent scheduled job it does nothing or just errors out. Anyone have any ideas as to what is happening?
Avatar of Dale Harris
Dale Harris
Flag of United States of America image

Avatar of Lydia626
Lydia626

ASKER

Hello again Dale ^_^

I did take those steps, trying to run the script you helped me out with earlier as a scheduled sql job now and running into this roadblock.
If I pass the function name in the scheduled job I get the following error

The error it is shooting back is
Executed as user: Hostname\SYSTEM. A job step received an error at line 1 in a PowerShell script. The corresponding line is 'get-Daily'. Correct the script and reschedule the job. The error information returned by PowerShell is: 'The term 'get-Daily' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.  '.  Process Exit Code -1.  The step failed.

IF I try passing the PS file name instead I get a different error that I will provide in a moment
If I just give the sql job the path to the file name as its job step it says the job completes but nothing the script has been written for happens. If I run the script outside of SQL it does what it is intended.

here is the error after a "successful" complete from SQL job agent.

 The job script encountered the following errors. These errors did not stop the script:  A job step received an error at line 37 in a PowerShell script. The corresponding line is '$backupname = get-childitem -name -path $path\$item\*.bak '. Correct the script and reschedule the job. The error information returned by PowerShell is: 'Cannot find drive. A drive with the name 'x' does not exist.  '  A job step received an error at line 37 in a PowerShell script. The corresponding line is '$backupname = get-childitem -name -path $path\$item\*.bak '. Correct the script and reschedule the job. The error information returned by PowerShell is: 'Cannot find drive. A drive with the name 'x' does not exist.  '.  Process Exit Code 0.  The step succeeded.  
ASKER CERTIFIED SOLUTION
Avatar of Dale Harris
Dale Harris
Flag of United States of America 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
If it's a network drive the RUN AS-user must have netwwork-authorisation, not a local user.
Part of the process is to put in the credentials of the user during the setting up process.  I agree with jogos that you should try the same account that the script works with when you run it by yourself.