Pls try this syntax:
- powershell.exe -noprofile -executionpolicy bypass -NoExit -File d:\myscript.ps1
The "-NoExit" argument will keep the PS window open. That way, you can know if an error was generated.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
Pls try this syntax:
The "-NoExit" argument will keep the PS window open. That way, you can know if an error was generated.
Hi, I'm Elise, and I'd be happy to help with your issue.
For this type of issue I would recommended posting in the Q&A forum, as this is the intended audience for these type of queries:
https://learn.microsoft.com/answers/
Kind Regards,
Elise
This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.
Comments have been turned off. Learn more
THANK YOU SO MUCH
The '-NoExit' helped give me the error and I fixed the issue!
I can't thank you enough!
This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.
Comments have been turned off. Learn more