Powershell batch job fails when run as a scheduled task.


My NAS is a Synology DS223. Largest file is probably a few MB. Total when compressed is currently around 1.8 GB
 

My Computer My Computer

At a glance

Windows 11Ryzen 9 9900
OS
Windows 11
Computer type
PC/Desktop
Manufacturer/Model
AMD Custom
CPU
Ryzen 9 9900
The Synology DS223 supports both Btrfs and ext4 for its internal storage volumes. During normal DSM setup, Btrfs is the recommended and typically selected file system, but it is not an immutable factory default; the file system is chosen when the volume is created

Unless you changed it to mount an old FAT32 file system it supports much higher file sizes.


Windows is accessing the NAS through SMB, not directly mounting the underlying Btrfs or ext4 file system.

That means:
  • Windows does not need Btrfs or ext4 support.
  • The NAS handles its internal file system.
  • Windows sees the shared folder as a network file share.
  • The NAS volume’s limits still apply, including the approximately 16 TiB maximum individual file size.
  • FAT32’s 4 GB limit is irrelevant unless the destination is actually an external FAT32-formatted USB drive attached to the NAS.

Therefore, copying a large file from Windows to:
\\NAS\Backups

should allow files larger than 4 GB, 100 GB, or 1 TB, provided:
  1. The Synology shared folder resides on Btrfs or ext4.
  2. The NAS has enough free space.
  3. The application performing the copy supports the file size.
  4. SMB2 or SMB3 is being used, which is normal on current Windows and DSM systems.

Do you know for certain how the drive was setup? @jpullam
 

My Computer My Computer

At a glance

Windows 11 Pro build 25H2 x64Intel i9-13900K64GBNvidia GeForce RTX-3090 Ti
OS
Windows 11 Pro build 25H2 x64
Computer type
PC/Desktop
Manufacturer/Model
ASUS Custom build
CPU
Intel i9-13900K
Motherboard
Asus ROG STRIX Z790 E GAMING WIFI 11
Memory
64GB
Graphics Card(s)
Nvidia GeForce RTX-3090 Ti
Internet Speed
1 Gbps
Browser
Firefox
Antivirus
Malwarebytes
I appreciate the effort you are putting in to help me, but I think I am going in a good direction now.

To answer your question I built the NAS about 3 months ago and I'm petty sure that I went with the defaults. I have lots of space on the two 4TB droves I installed.

I have been working with 7-zip for a few hours and I now have what seems to be a good functioning bat file. It is as follows:

@echo off
set "SZ=C:\Program Files\7-Zip\7z.exe"
set "DEST_DIR=\\NAS3\Backups\MyDocsArchives"
set "SRC_DIR=\\NAS3\Backups\MyDocsCopy\*"
set "DATE_STAMP=%date%
REM Compress the folder using the date in the filename
"%SZ%" a "%DEST_DIR%\MyDocsArchive_%DATE_STAMP%.7z" "%SRC_DIR%\*"

This creates the back up I want and I think all that is left is for me to set it up in the scheduler.
 

My Computer My Computer

At a glance

Windows 11Ryzen 9 9900
OS
Windows 11
Computer type
PC/Desktop
Manufacturer/Model
AMD Custom
CPU
Ryzen 9 9900
The following is my code
The root cause of the issue is the use of the mapped drive letter N:\. When the Task Scheduler runs the script in the background at night, the N:\ drive does not exist for that session. Windows only mounts mapped network drives for an active, logged-in user session.
As a result, the Compress-Archive cmdlet fails immediately because it cannot find the path, and the Task Scheduler simply logs a very fast process creation (Event ID 129) and exits.
## The Solution: Use UNC Paths
To fix this, you need to replace the drive letter N:\ with the direct network UNC path to your Synology NAS.
An example of a corrected and optimized version of the script

Code:
# 1. Define your Synology NAS IP address or network name (e.g., \\SynologyNAS\)
$NasServer = "192.168.1.100" # Replace with your actual Synology IP or hostname
# 2. Define source and destination using UNC network paths instead of N:
$SourcePath     = "\\$NasServer\MyDocsCopy\*"
$Timestamp      = Get-Date -Format "yyyy-MM-dd"
$DestinationZip = "\\$NasServer\MyDocsArchives\MyDocsArchive_$Timestamp.zip"
# 3. Create the ZIP archive directly on the network share
Compress-Archive -Path $SourcePath -DestinationPath $DestinationZip -Force
## Critical Task Scheduler Settings
To make sure this script runs properly on Windows 11 while you are asleep, verify these settings in the Task Scheduler task properties:
* General Tab:
* Select "Run whether user is logged on or not". This ensures the task runs at night.
* Check "Run with highest privileges" (Administrator mode).
* Make sure the user account assigned to run the task is the same Windows account you use to access the Synology NAS.
* Actions Tab:
* Program/script: powershell.exe
* Add arguments: -NoProfile -ExecutionPolicy Bypass -File "C:\PathToYourScript\backup.ps1"
* The -Force Parameter: I added -Force to the Compress-Archive command. If the script accidentally triggers twice on the same day, it will overwrite the existing file instead of crashing with a "File already exists" error.

If the task still ends too quickly after these changes, let me know if Windows remembers your Synology credentials automatically (via Windows Credential Manager) or if you have to type a username and password whenever you access the NAS network folder manually.
 

My Computer My Computer

At a glance

Windows 11 Insider Experimental (26H2)Intel Core i5-1140032Gb (DDR4 SDRAM)Intel(R) UHD Graphics 730
OS
Windows 11 Insider Experimental (26H2)
Computer type
PC/Desktop
Manufacturer/Model
Gigabyte Technology Co., Ltd.
CPU
Intel Core i5-11400
Motherboard
Z590 AORUS PRO AX
Memory
32Gb (DDR4 SDRAM)
Graphics Card(s)
Intel(R) UHD Graphics 730
Sound Card
Realtek USB Audio
Monitor(s) Displays
LG 27US500-W 4K UHD UltraFine™
Screen Resolution
3840x2160
Hard Drives
Samsung SSD 980 PRO 1TB
WDC WD7501AALS
PSU
Montech CENTURY, 650W, 80+ Gold
Case
Cougar Airface ECO RGB
Cooling
ID-COOLING SE-224-XTS BLACK
Keyboard
Microsoft SideWinder X6 Keyboard
Mouse
Microsoft SideWinder Mouse
Internet Speed
Internet speed of 1 Gbit/s
Browser
Vivaldi browser
Antivirus
Windows Defender
Take a look at the following script @jpullam

Modify to your needs or keep what you have. Just sharing ideas that work for me.
 

My Computer My Computer

At a glance

Windows 11 Pro build 25H2 x64Intel i9-13900K64GBNvidia GeForce RTX-3090 Ti
OS
Windows 11 Pro build 25H2 x64
Computer type
PC/Desktop
Manufacturer/Model
ASUS Custom build
CPU
Intel i9-13900K
Motherboard
Asus ROG STRIX Z790 E GAMING WIFI 11
Memory
64GB
Graphics Card(s)
Nvidia GeForce RTX-3090 Ti
Internet Speed
1 Gbps
Browser
Firefox
Antivirus
Malwarebytes
Back
Top Bottom