Solved

Task Scheduler & PowerShell Script

Posted on 2014-10-23
6
377 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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
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.
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

617 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