How to run a powershell with parameters using a Batch file(or run it via Task Scheduler)

It might be that the Powershell instance that is spawned does not have access to the mapped drive because it is only accessible in the current shell process, but that doesn't really make sense since you're mounting it to a drive letter.

Out of curiosity, does it work if you run the powershell script straight from the Task Scheduler without wrapping it in batch? Something like

program: powershell.exe
arguments: -NoProfile -ExecutionPolicy Bypass -Command "& 'D:\path\to\script\ArchiveMailv2.ps1' -path 'E:\path\to\folder\domain.com\user1\' -Arcfolder '\path\to\backup$\ArchiveMail\user1\' -days 180; & 'D:\path\to\script\ArchiveMailv2.ps1' -path 'E:\path\to\folder\domain.com\user2\' -Arcfolder '\path\to\backup$\ArchiveMail\user2\' -days 180"

/r/PowerShell Thread