1
votes

I guess this is easy but is eluding me, I have a working Powershell script that I wish to run as a Scheduled Task in Windows 10, however the script does not execute from the Task scheduler.

Script is hider.ps1

$fs = New-Object -ComObject scripting.filesystemobject
Get-ChildItem "D:\TV Shows\" -force | Where-Object {$_.psiscontainer} | ForEach-Object {
    if($fs.getfolder($_.fullname).size -lt 20mb) {$_.attributes = "directory,hidden"}
    else{$_.attributes = "directory"}
}

This hides empty folders in a directory

In Task scheduler I have put

Start a program Powershell

Arguments -ExecutionPolicy Bypass –File "F:\Xaved Files\Hider ps 1"

1
Do you see the terminated status in task scheduler? Was it 0x0 or an error? - AndreaTaroni86
I get Task scheduler successfully completed task with return code 1 - pjzapped
So.. Microsoft identifies it with 1 or 0x1: Incorrect function called or unknown function called. It's not a solution maybe, but please try this: 1-create a batch file that calls your script and verify that it works 2-schedule your batch indicating the starting folder as batch and script's directory. Does it works? - AndreaTaroni86
@andreataroni86 Hi Andrea thanks - the script definitely works, if I run it in in Powershell directly it works fine, I have tried your suggestion but when the script is called it still is not running. It must be something to do with Windows 10 permissions but I am having no luck - pjzapped
have you configured the task with local admin profile and checked "use hightest privilege" in task configuration? - AndreaTaroni86

1 Answers

1
votes

Have you set the "start in" directory???

Apparently, since windows server 2012, if a task doesn't have this field informed, the task doesn't run silently.

This worked in my case, and also to this guy