Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Problem running Powershell Scripts scheduled through Task scheduler under Win 2003

Posted on 2007-11-26
3
Medium Priority
?
2,795 Views
Last Modified: 2010-04-21
Hi there,
I have a problem getting a powershell script to run automatically once a day.

I created a script to automatically backup some files from my server to another server. The scipt source is attached.

When I run the script from powershell, it works like a charm. However, when I create a task in Windows task scheduler (on my W2003 server), the script itself gets called (I can tell because the email is being sent), but nothing else happens. cp tells me '0 files copied'.

I don't understand this. How can the script run flawlessly when called directly and then seem not to find any paths when being called by taskscheduler.
I tried different ways of calling the script in task scheduler, inculding a .cmd wrapper that only calls 'powershell script.ps1', but nothing seems to work.

And yes, i did associate ps1 files with powershell, and I also set the security policy to remote signed.

Any help would be greately appreciated, as this is driving me nuts!

Thanks a lot,

Andreas
echo "Datensicherung :  Projektliste taeglich" > protokoll.txt
echo "Alte Dateien löschen (älter als 60 Tage)"  >> protokoll.txt
delage32 \\MYSERVER\NASBackup\Projektliste\*.* 60 /created /includeRO /includeH >> protokoll.txt
echo "" >> protokoll.txt
 
mkdir \\MYSERVER\NASBackup\Projektliste\temp
cp E:\FilesToBeBackuped\* -destination \\WS-NET1-TS\NASBackup\Projektliste\temp -force -verbose:$true >> protokoll.txt
FBZip.exe -a -p -r \\MYSERVER\NASBackup\Projektliste\temp\Projektliste.zip \\MYSERVER\NASBackup\Projektliste\temp\ | out-null
cp \\MYSERVER\NASBackup\Projektliste\temp\Projektliste.zip -destination \\MYSERVER\NASBackup\Projektliste\Projektliste.zip >> protokoll.txt
NameDate.exe /F /U /Y /Z:Y-m-d \\MYSERVER\NASBackup\Projektliste\Projektliste.zip >> protokoll.txt
rm \\MYSERVER\NASBackup\Projektliste\Projektliste.zip >> protokoll.txt
rm -r \\MYSERVER\NASBackup\Projektliste\temp
 
get-ChildItem \\MYSERVER\NASBackup\Projektliste  >> protokoll.txt
 
CommandlineEmailer /smtp:mail.mydomain.de /to:administrator@mydomain.de /s:"Sicherung Projektliste" /i:protokoll.txt
 
rm protokoll.txt

Open in new window

0
Comment
Question by:ifnt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
markpalinux earned 1500 total points
ID: 20349514

Can you try
a .cmd wrapper that only calls 'powershell script.ps1 > script-log.txt'
so they results / output is dumped to the log.

Can you also call the cmd manually to see if anything happens?

Then check the differences between the files.

maybe add in before any cp line a dir. - like "dir E:\FilesToBeBackuped\* > E-FilesToBeBackuped-dir.txt"

Mark

0
 

Author Closing Comment

by:ifnt
ID: 31410960
Ok, I found the problem thanks to your tip concerning piping the script output to a log file and looking at it.
For the records: The problem was due to an authentication problem. The server I was trying to write to was a Buffalo NAS device. It is set up to do authentication against our Active Directory domain. However, it was not doing as it was telling it was, so the Domain Administrator user, as who I ran the script from within task scheduler, had no write access to that share on the NAS. When manually running the script from within my own window session, it worked fine, because my user had the appropriate rights on the Buffalo NAS.
I don't understand this NAS device, but now it works.
Thanks!
0
 

Author Comment

by:ifnt
ID: 20350593
Ok, I found the problem thanks to your tip concerning piping the script output to a log file and looking at it.
For the records: The problem was due to an authentication problem. The server I was trying to write to was a Buffalo NAS device. It is set up to do authentication against our Active Directory domain. However, it was not doing as it was telling it was, so the Domain Administrator user, as who I ran the script from within task scheduler, had no write access to that share on the NAS. When manually running the script from within my own window session, it worked fine, because my user had the appropriate rights on the Buffalo NAS.
I don't understand this NAS device, but now it works.
Thanks!
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've always wanted to allow a user to have a printer no matter where they login. The steps below will show you how to achieve just that. In this Article I'll show how to deploy printers automatically with group policy and then using security fil…
A quick step-by-step overview of installing and configuring Carbonite Server Backup.
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question