troubleshooting Question

CANNOT Get PShell Working On Windows 2012 R2 Via Task Scheduler

Avatar of Michael O'Hara
Michael O'Hara asked on
5 Comments1 Solution88 ViewsLast Modified:
Am trying to run script to archive files - the job runs perfectly running manually & through command prompt, but will not complete when run via Task Scheduler (even though it says the job ran).

I have seen (many) articles with switches and different ways to get around this but no luck.   Have confirmed account has "log on as batch" rights and also a local admin.   Also has rights to the network folder.

function doTheSort([string]$SourceDir, [string]$DestinationDir) 
{$files = get-childitem $SourceDir -Include @("*.txt","*.log", "*.gtm", "*.x340", "p*") 
 #$files = get-childitem $SourceDir -Exclude @("Archive","BAI Files","ICMS Output","restore","TEST-ARCH")
    foreach ($file in $files)
        $Directory = $DestinationDir + "" + $file.lastwritetime.Date.ToString('yyyy') + "\" + $file.lastwritetime.Date.ToString('MMM') + "\" + $file.lastwritetime.Date.ToString('dd')

        if (!(Test-Path $Directory))
            New-Item $directory -type directory
        Copy-Item $file.fullname $Directory 

doTheSort "I:\Prior Day files for Upload" "C:\DIR-TEST\"

Any suggestions?
Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros