Hi there,
If the task scheduler works only when you plug the Laptop try changing the Power Conditions for the task and see if that helps. To do this, refer the steps mentioned below:
-Press Windows logo key + R, to open Run dialog box.
-Type taskschd.msc and click on OK.
-Click on Task Scheduler Library.
-Double click on the task that you have created, navigate to the Conditions tab.
-Under Power, clear the checkbox for Stop if the computer switches to battery power.
--If the reply is helpful, please Upvote and Accept it as an answer--