Just add this before your code in the .ps1 file:
#Load SharePoint PowerShell SnapIn
if ( (Get-PSSnapin -Name Microsoft.Sharepoint.Powershell -ErrorAction SilentlyContinue) -eq $null )
This will load the required Snapin. Then all the SharePoint commands should work.
If you want to stop a running workflow ...
I like the powershell approach mentioned by Denis, but I'd go further and code the powershell to just do the task that is done by the js. Having a visible IE window run by a process that should be able to run with no one logged in is going to surprise any admins who need to work with this script.
It sounds like a very weird case, but you can still do it.
Very roughly, this is what it takes:
Create a separate SharePoint page with a Content Editor Web Part (CEWP)
Optional. Make sure this page can only be accessed by certain accounts
Add your script to the CEWP.
Create a PowerShell file (.ps1) that will open your SharePoint page with the script
I have done this in SPD by looping through the list once a day. Create a workflow that loops through each item in the list, and sends each email based on the date and then goes to sleep for 23 hours and 49 minutes.
Unfortunately, it's not possible
The roll-up feature that used to auto calculate the overall %Complete is not available in the SharePoint Tasks list.
It's only available in the Project Schedule in Project Server & Microsoft Project.
While it might be possible using SharePoint 2013 style workflows, the workflow would be complicated and would have to make quite a few REST API web service calls to keep rerequesting the list data after each update. (each edit could change the order the tasks by date.)
Task scheduling can get very complex. Here's a few things to consider:
The workflow ...
If it's in a database why not use the BCS to create an External Content Type? Then create a secondary import connection in the User Profile Service and have the properties updated when the Synchronization Timer Job runs?
If not then you could just run it as a Windows scheduled job. Heck, you could even ditch the C# for PowerShell.
You can certainly encrypt / decrypt a string with powershell. So, you could have one utility script that's run just to get the password and save it as an encrypted string in a file. When the main script runs, it would read that file and decrypt the string. Instructions for this are here: