I have two script to use as part of an application install. The first script creates a scheduled task to run the second script after the server reboots. That portion of the script is:
$installScript = "$PSScriptRoot\Install.ps1"
schtasks.exe /CREATE /F /TN "Install Application" /RU $taskUser /SC ONLOGON /IT /TR "powershell.exe -ExecutionPolicy Bypass -File $installScript" /RL HIGHEST
This has worked really well for me, but I just discovered a hitch. When $PSScriptRoot
has spaces in it, the scheduled task fails to find the Install.ps1 script. I've found if I edit the argument in the scheduled task to include "" around the path, it works without issue. But I'm not sure how to accomplish that. Anyone have a suggestion?