Fixed: When running a PowerShell script in the IDE it finishes fine, but when I run the same PowerShell script via the Task Scheduler the task never finishes.
To fix this, instead run a batch file that calls the PowerShell script thusly:
Powershell.exe -executionpolicy remotesigned -File C:\script.ps1
The task should then finish without issue, though I don’t know why it does this because the script itself doesn’t seem to need elevating as it seems to run (but not finish) as a PowerShell script.
Other sources on the internet mention fixing the problem by ticking the box in Task Scheduler to Run With Highest Privileges, though I didn’t have any luck with that option.