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?
Lydia626Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dale HarrisProfessional Services EngineerCommented:
0
Lydia626Author Commented:
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.
0
Lydia626Author Commented:
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
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Lydia626Author Commented:
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.  
0
Dale HarrisProfessional Services EngineerCommented:
It looks like the "X" drive isn't working for SQL, but it's working for you.

Does X exist natively on your SQL Server, or just your local computer?

if X is a network drive, try using the full path.

If all that doesn't work, we can try some simple commands with "X" drive to make sure it's working.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jogosCommented:
If it's a network drive the RUN AS-user must have netwwork-authorisation, not a local user.
0
Dale HarrisProfessional Services EngineerCommented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.