Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources: Active Threads
Viewing all articles
Browse latest Browse all 8411

How can I schedule this simple powershell script 3.0 to run using Win Server 2012?

$
0
0

This simple copy line in powershell runs interactively but when I try to schedule in Windows task scheduler, it shows that it completed but it did no work. I.e., it did not copy the file. I tried using the steps listed in "Run PowerShell Scripts from Task Scheduler" but still no luck. If anyone can give me some advice, I would be greatful. Below is the one line script (using UNC paths gets multiple access prohibited errors) If I could get the share names working first, that would be a start.

V:\ is a path mapped to a Windows 7 drive and D:\ is on the Windows 2012 server. The task history gives task start and stop times but no detailed info.

Copy-Item -Path V:\data\bar\foo\Outlook\*.pst -Destination D:\Data\foobar\Outlook 
Tried Using "net use" to map a network drive but the script "hangs" as per advice on another board: 

"you need to add a net use command to re-map the drive so that your scheduled task can see it 
(because it's not the same account being used to run the task), or be sure it is running only while a user account is 
logged in)"

So here is the complete script: 

net use V: \\WINDOWS7\CDrive /user:USER1 PASSWORD123
Copy-Item FILESYSTEM::V:\data\bar\foo\Outlook\*.pst D:\Data\foobar\Outlook

A follow-up question is how would I debug a running task that uses said above script:  

PowerShell.exe -ExecutionPolicy Bypass SIMPLECOPYITEM_SCRIPT.PS1
Again, this just hangs



Viewing all articles
Browse latest Browse all 8411

Latest Images

Trending Articles



Latest Images