Powershell running as batch on Scheduled Task on Server

Good Morning Folks!

I have a powershell script that runs as part of a batch process. When I run the batch file manually, the code where I change the number format in one field to % works. However, when I run the batch file on a scheduled task, the PS file runs, however the part of the file that changes the number in the one field to % doesn’t seem to work. Below is the code that runs that part of the PS Script. Any ideas what adjustments I can make so that this part of the script completes on the scheduled task?

I have: run as administrator, user has all proper permissions to PS, verified that the batch file runs the PS and that the script does what it is supposed to do manually running the batch

$file1 = "D:\autoloader\Secure_Bulk\SES_Live.csv"
$xl = new-object -c excel.application
$xl.displayAlerts = $false
$wb1 = $xl.workbooks.open($file1)
$ws1 = $wb1.WorkSheets.item(1)
$n = $ws1.UsedRange.Rows.Count
while($r -lt $n) {
  if ($ws1.Cells.Item($r, "AR").Text -eq "Company Name") {
    $ws1.Cells.Item($r, "J").NumberFormat = "0.00%"


I should add: this is running on Windows Server 2019 Datacenter, where when I run it on Task Scheduler on a Windows 10 machine I have no issues and it completes successfully.


Excel is well known for not beeing supported to run without an interactive session as scheduled task. Instead you can use the great module from Doug Finke ImportExcel. You don’t even have to have Excel installed on the machine where you want to use it. :wink:

Thanks Olaf! Now I just need to learn how to change my script to use this module. I have it installed now. Do I have to change the commands or it knows to use it?

1 Like