I have a Powershell script to copy .mkv and .mp4 files from Downloads to my Plex server. The script works fine on its own.
I schedule it to run every 30 minutes using Schtasks and it runs fine. Except a PS window appears on each run.
This thread https://stackoverflow.com/a/1802836/4934442 indicates that going to Task Scheduler and setting the option to "Run whether user is logged on or not" will prevent the window from showing.
When I set this option, the Copy-Item in my script fails to execute. It won't copy to my Plex network share and it won't copy to a local folder. (The Remove-Item does execute). I have worked around this issue by using "pscp" to my Plex server, but I would like to find a way for Copy-Item to function for future scripts running in the background.
Note: one comment in the reference thread mentioned a similar problem
The script:
$mypath='C:\Users\rammjet\Downloads\'
$mydest='Z:\a_watch_folder'
$myext='*.mkv','*.mp4'
foreach($ext in $myext)
{
$mysearch=$mypath + $ext
$mylist=dir $mysearch -Name
foreach($myfile in $mylist)
{
$myfile=$mypath + $myfile
$mytest=$myfile + '.part' # in process of download
if (!(Test-Path $mytest))
{
Copy-Item $myfile -Destination $mydest
Remove-Item $myfile
}
}
}