Solved

Task Scheduler & PowerShell Script

Posted on 2014-10-23
6
361 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
[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
  • 3
  • 3
6 Comments
 
LVL 70

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 70

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 70

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

710 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