Windows 10: Powershell Script .ps1 file Does Not Work When Executed Through Task Scheduler

Discus and support Powershell Script .ps1 file Does Not Work When Executed Through Task Scheduler in Windows 10 Software and Apps to solve the problem; Hi there, I have created a .ps1 file which contains a RoboCopy script to copy files from a folder on my C: drive which contains a database, and paste... Discussion in 'Windows 10 Software and Apps' started by BhavanBaijnath, Nov 30, 2022.

  1. Powershell Script .ps1 file Does Not Work When Executed Through Task Scheduler


    Hi there, I have created a .ps1 file which contains a RoboCopy script to copy files from a folder on my C: drive which contains a database, and paste them into a folder on my OneDrive so that they can be safely backed up to the cloud and have a history of changes.The code runs perfectly fine when executed manually By right-clicking the file in File Explorer and selecting 'Run with Powershell', the problem is that the backup needs to happen on a regular basis, hourly is ideal, so I created a task inside of Task Scheduler to repeat the task every hour. The task itself runs fine I tested this

    :)
     
    BhavanBaijnath, Nov 30, 2022
    #1

  2. Powershell Script (.ps1 file) Does Not Work When Executed Through Task Scheduler

    Hi there, I have created a .ps1 file which contains a RoboCopy script to copy files from a folder on my C: drive which contains a database, and paste them into a folder on my OneDrive so that they can be safely backed up to the cloud and have a history of changes.

    The code runs perfectly fine when executed manually (By right-clicking the file in File Explorer and selecting 'Run with Powershell'), the problem is that the backup needs to happen on a regular basis, hourly is ideal, so I created a task inside of Task Scheduler to repeat the task every hour. The task itself runs fine (I tested this by changing what the action is when the task is triggered to open a program instead).

    The problem is that when I change the action to run Powershell and add the path of my file under the 'Add Arguments' section, the task does not work. The task still runs, Powershell loads, but then immediately closes and does nothing, however running the exact same file manually will work just fine.

    I have tried adding '-File'; '-Command'; 'ExecutionPolicy Bypass' and '-ExecutionPolicy Unrestricted' before the path of my file, but nothing happened.

    Am I doing something wrong or is there a setting that needs to be changed? I have done some research and found that it could possibly have something to do with the execution policy, I tried several things related to that (not sure if I did the right thing or if I did it right) but none of them seemed to work.

    I am using a Lenovo Ideapad S145 with an i5-7200U running Windows 10 Version 21H2 Build 19044.2130


    Powershell Script .ps1 file Does Not Work When Executed Through Task Scheduler 0e8f59fd-0cb6-491c-a5f2-5a80b3372c7c?upload=true.png
     
    BhavanBaijnath, Nov 30, 2022
    #2
  3. Szewczyk Win User
    Setting .PS1 scripts default program to Powershell is soooooooooooo freak'in difficult

    In Windows 10, .PS1 by default program is set to notepad, yeah go wonder, even though the description for a .PS1 file is "Windows Powershell Script", then of course trying to set it to Powershell brings up a dialog that asks "Which app do you want it to
    set to" and of course there is no app named Powershell. Then the dialog wants you to search the computer to find Powershell even though it is Microsoft's major player in scripting, the Windows 10 can't find, I have to hunt and peck to find the executable.
     
    Szewczyk, Nov 30, 2022
    #3
  4. Powershell Script .ps1 file Does Not Work When Executed Through Task Scheduler

    Powershell Scripts in the Windows 10 OS and script execution policy of "Allow only Signed scripts"

    We have the group policy " Turn on Script execution" enabled and set to "Allow only Signed scripts".

    Will this affect the powershell scripts used in the Windows 10 operating System or does windows have something inbuilt that overrides the settings we apply. I'm thinking that it would block even the W10 built in scripts.

    An example of what I am talking about are the 246 .ps1 files in the various diagnostic directories in c:\windows\diagnostics\system\ . our diags never come back with issues even when deliberately disabling components before running.

    other areas that Powershell scripts live that I have found with a quick search -

    C:\Windows\WinSxS\wow64_microsoft.powershell.odatautils_31bf3856ad364e35_10.0.17763.1_none_d60dcab1d9234fab

    C:\Program Files (x86)\WindowsPowerShell\Modules\Microsoft.PowerShell.Operation.Validation\1.0.1\Diagnostics\Comprehensive

    C:\Program Files\WindowsPowerShell\Modules - various folders in here.

    Do we need to sign all powershell scripts that come with the OS?

    Does Microsoft have a method of doing this?

    Is there a list of script files that come with the OS so we don't just do a sign all approach, then find we have signed malware files.

    we could probably configure something in the build task sequence to sign what is there initially. Is there any plan in place for Microsoft to start signing their scripts?

    Will this be an ongoing process as updates are applied and files replaced, do we need to have a process in place to sign all PS1 files in the OS?
     
    Paul Klerkx(psk), Nov 30, 2022
    #4
Thema:

Powershell Script .ps1 file Does Not Work When Executed Through Task Scheduler

Loading...
  1. Powershell Script .ps1 file Does Not Work When Executed Through Task Scheduler - Similar Threads - Powershell Script ps1

  2. I can not run a powershell script through Task Scheduler when the useris logged on or not

    in Windows 10 Gaming
    I can not run a powershell script through Task Scheduler when the useris logged on or not: i have a powershell script used to 1 change date format2 convert from xlsx to csvand needs to be automated and run everyday.The user account used SPO... can run the script manually and it works. the moment its on task scheduler it wont work aprt if the setting is set to "run...
  3. I can not run a powershell script through Task Scheduler when the useris logged on or not

    in Windows 10 Software and Apps
    I can not run a powershell script through Task Scheduler when the useris logged on or not: i have a powershell script used to 1 change date format2 convert from xlsx to csvand needs to be automated and run everyday.The user account used SPO... can run the script manually and it works. the moment its on task scheduler it wont work aprt if the setting is set to "run...
  4. Task scheduler not executing executable file properly

    in Windows 10 Gaming
    Task scheduler not executing executable file properly: I am executing a bat file which is calling a power shell script.Power shell script is doing the below activity.Step1: It truncat the table and insert it from the file present in the server.Step2: execute the executable file.Step3: create the file and archive it in the...
  5. Task scheduler not executing executable file properly

    in Windows 10 Software and Apps
    Task scheduler not executing executable file properly: I am executing a bat file which is calling a power shell script.Power shell script is doing the below activity.Step1: It truncat the table and insert it from the file present in the server.Step2: execute the executable file.Step3: create the file and archive it in the...
  6. Task scheduler not executing executable file properly

    in Windows 10 Customization
    Task scheduler not executing executable file properly: I am executing a bat file which is calling a power shell script.Power shell script is doing the below activity.Step1: It truncat the table and insert it from the file present in the server.Step2: execute the executable file.Step3: create the file and archive it in the...
  7. Powershell Script .ps1 file Does Not Work When Executed Through Task Scheduler

    in Windows 10 Network and Sharing
    Powershell Script .ps1 file Does Not Work When Executed Through Task Scheduler: Hi there, I have created a .ps1 file which contains a RoboCopy script to copy files from a folder on my C: drive which contains a database, and paste them into a folder on my OneDrive so that they can be safely backed up to the cloud and have a history of changes.The code...
  8. Powershell Script .ps1 file Does Not Work When Executed Through Task Scheduler

    in Windows 10 Gaming
    Powershell Script .ps1 file Does Not Work When Executed Through Task Scheduler: Hi there, I have created a .ps1 file which contains a RoboCopy script to copy files from a folder on my C: drive which contains a database, and paste them into a folder on my OneDrive so that they can be safely backed up to the cloud and have a history of changes.The code...
  9. Powershell script does not run via Task Scheduler

    in Windows 10 Customization
    Powershell script does not run via Task Scheduler: PowerShell script runs fine manually, but doesn't run in Task scheduler. The script: [ATTACH] I tried another command$env:COMPUTERNAME and works fine both manually and via PowerShell....
  10. PowerShell script does not run as Scheduled Task – 0xFFFD0000 error

    in Windows 10 News
    PowerShell script does not run as Scheduled Task – 0xFFFD0000 error: [ATTACH] [ATTACH]The Windows 10 Task Scheduler is a boon for a group of users who like to schedule different tasks and automate them. I use it all the time to schedule periodic execution of scripts and some programs to ensure my [...] This post PowerShell script does not run...