Solved

Task Scheduler & PowerShell Script

Posted on 2014-10-23
6
338 Views
Last Modified: 2014-10-29
Hello Experts,

I'd like to create a task in the task scheduler to automatically run a powershell script that:

1. map a network drive with credential (\\servername\folderA\subfolderA, username, password)
2. execute the script TOTO.VBS
3. copy the script to my physical c:\ drive, not the VM one (\\Tsclient\c\results)
4. unmap the network drive

Can you help?
0
Comment
Question by:mldaigle1
  • 3
  • 3
6 Comments
 
LVL 68

Expert Comment

by:Qlemo
ID: 40399478
That does not make (much) sense, and even if I would rather stay with a traditional cmd batch file.

"copy the script" - you probably mean the results generated by the script? Which is a file?
"\\Tsclient\c\results" - that requires you to have a terminal client session (RDP) open, or the VM console (probably its Virtual PC?).
0
 

Author Comment

by:mldaigle1
ID: 40399620
oops  your right.... copy the result TXT to my physical workstation and yes i do a RDP to a VMware session
0
 
LVL 68

Accepted Solution

by:
Qlemo earned 500 total points
ID: 40399711
As .cmd file (PS is oversized here):
@echo off
net use \\servername\folderA  /u:username password
pushd \\servername\folderA\subfolderA
cscript //nologo TOTO.VBS
copy TOTO.TXT \\Tsclient\c\results
popd
net use \\servername\folderA /d

Open in new window

You should be able to provide just the batch file name including path when creating the scheduled task.
0
Does Powershell have you tied up in knots?

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

 

Author Comment

by:mldaigle1
ID: 40400076
Hello Qloemo,

The CMD works fine but it does not work through the task scheduler, getting error 0x02
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 40400595
Which account did you provide for the task? It needs to be some user account, not local system or the like.
For further troubleshooting allow the task to run as your current interactive user, and add
  pause
as last command in the batch file. You should see then if an error is reported.
0
 

Author Comment

by:mldaigle1
ID: 40411977
thanks for your help
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

896 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now