问题
My requirement was to copy certain files from remote machine to the local machine and I have written mapped the folder to the local machine.I use the drive letter of the mapped folder and the script works fine. But when I schedule the task, it throws error that the drive doesn't exists or isn't mapped.
Please find the script below:
$destination = "D:\Script\"
$source = "T:\"
$datefolders = Get-ChildItem $source
$TodayString = (Get-Date).ToString("yyyy-MM-dd")
foreach($folder in $datefolders)
{
$foldername = $folder.ToString()
if ($foldername -eq $TodayString)
{
$path1 = $source + $foldername + "\*\*.csv"
Copy-Item -Path $path1 -Destination $destination -Force
$allfiles = Get-ChildItem "D:\Script\"
foreach($file in $allfiles)
{
$filename = ([io.fileinfo]$file).basename
$filepath = $destination + $file
$connectorfolder = "D:\Script\" + $filename + "\"
Move-Item -Path $filepath -Destination $connectorfolder -Force
}
break
}
}
Please note that the script works fine when ran directly. Please help me on how I can provide the remote server details which is shown as "T:\" drive in my script.
The error I can see in Event viewer is given below:
Error Message = Could not find the drive 'T:\'. The drive might not be ready or might not be mapped.
Please help.
Regards,
Mitesh Agrawal
来源:https://stackoverflow.com/questions/61291654/how-to-schedule-a-ps-script-in-task-scheduler-which-copies-files-from-remote-com