• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 436
  • Last Modified:

Task Scheduler & PowerShell Script

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
mldaigle1
Asked:
mldaigle1
  • 3
  • 3
1 Solution
 
QlemoDeveloperCommented:
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
 
mldaigle1Author Commented:
oops  your right.... copy the result TXT to my physical workstation and yes i do a RDP to a VMware session
0
 
QlemoDeveloperCommented:
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
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

 
mldaigle1Author Commented:
Hello Qloemo,

The CMD works fine but it does not work through the task scheduler, getting error 0x02
0
 
QlemoDeveloperCommented:
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
 
mldaigle1Author Commented:
thanks for your help
0

Featured Post

Will You Be GDPR Compliant by 5/28/2018?

GDPR? That's a regulation for the European Union. But, if you collect data from customers or employees within the EU, then you need to know about GDPR and make sure your organization is compliant by May 2018. Check out our preparation checklist to make sure you're on track today!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now