The folder where the script was present was
D:\Some Folder\script.ps1
The folder name had spaces. So when I added the action in the task scheduler to run a program/script , the scheduler itself would put apostrophes (" ") and the action would look something like below:-

After long struggle I found out that the apostrophes were causing the task scheduler not to run the script.
To fix this , there are two solutions :-
- Change the folder name to something without spaces
- Pass the script as argument. This can be done by changing the below:-
program /script : Powershell.exe
the argument : -file "D:\Your folder name with space\your_script.ps1"
Below is the grab from my task scheduler.

Hope this helps everyone who faces such problem .