IM&T SRFT
asked on
Powershell script not running when set as a Scheduled Task
I have created a script to take the files from one directory and copy them to others before deleting the original
The script runs fine in PowerShell locally but when putting as a scheduled task, the task scheduler is showing 'Task Completed' but the original file remains where it is and does not get copied.
Run Command Line - powershell -file "C:\Desktop\Demographic (Spine) Feed.ps1"
I have chosen to run with highest priviledges too
The script runs fine in PowerShell locally but when putting as a scheduled task, the task scheduler is showing 'Task Completed' but the original file remains where it is and does not get copied.
Run Command Line - powershell -file "C:\Desktop\Demographic (Spine) Feed.ps1"
I have chosen to run with highest priviledges too
# Copy everything under C:\Folder1 to C:\Folder2 & C:\Folder3
get-childitem "C:\Folder1" | % {
copy-item $_.FullName -destination "C:\Folder2\$_" -recurse
copy-item $_.FullName -destination "C:\Folder3\$_" -recurse
}
# Remove everything under C:\Folder1
get-childitem "C:\Folder1" -recurse | % {
remove-item $_.FullName -recurse
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
give a try with adding this line on top of your code
Set-ExecutionPolicy Bypass
ASKER
Thank you all very much
I deleted the task entirely and started again with the following changes and it now works
Bill - Thank you for your contribution throughout
Muhammad - I used that link before hand but still managed to get it wrong!
Michael - I split the command line and typed powershell.exe in full
Shaun - I initially removed the brackets in the name of the file and it still did not work but when I created the task again I removed all of the references to the brackets from the task including the task name and description and coinciding with the other changes this is where it all started to work again
I deleted the task entirely and started again with the following changes and it now works
Bill - Thank you for your contribution throughout
Muhammad - I used that link before hand but still managed to get it wrong!
Michael - I split the command line and typed powershell.exe in full
Shaun - I initially removed the brackets in the name of the file and it still did not work but when I created the task again I removed all of the references to the brackets from the task including the task name and description and coinciding with the other changes this is where it all started to work again
He already has the path quoted, in which case the parens and spaces in the file name pose no problem.
~bp