I'm having trouble getting this script to run correctly in Windows Servers 2012 R2 Task Scheduler, when I run it from PowerShell ISE it runs fine and copies the files to all 3 server mapped network drives, however, from Task Scheduler it only copies files to the last mapped drive and the bkup folder. I'm hoping you guys can help me get the right configuration, here's the code:
param (
$src = "C:\Users\user\Documents\SRC_FOLDER",
$bkup = "C:\Users\user\Documents\BKUP_FOLDER",
$SHARE1 = "\\SERVER1\SHARE\1",
$SHARE2 = "\\SERVER2\SHARE\2",
$SHARE3 = "\\SERVER3\SHARE\3"
)
$mappedUnits = $bkup, $SHARE1, $SHARE2, $SHARE3
foreach ($mappedUnit in $mappedUnits)
{
Get-ChildItem $src | Copy-Item -Destination $mappedUnit -Recurse -Force
}
#Get-ChildItem $src | Remove-Item
Task Scheduler is set to run as Domain Admin (also tried a local admin account) and as highest privileges, it runs every 10 minutes, it invokes powershell (with full path to .exe), with arguments: -ExecutionPolicy Unrestricted -File "MOVE-FILES.ps1" and the option Start in is set to the script's path.
I've tried many types of configuration and this is the latest one which, like I mentioned before, it works when executing manually but not from Task Scheduler.