Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Windows schedules task creation issue with powershell
- # Create the script file the schedule task will call, note path contains a space
- 'set-content c:tempprogram filesa.log "Just done @ $(get-date)"' > 'c:tempprogram filesa.ps1'
- $scriptFilePath = 'c:tempprogram filesa.ps1';
- $userName = read-host 'user name'; # will need log on as batch rights
- $userPassword = read-host 'user password';
- # The following looks good but schtasks args gets messed up so no creation
- $taskToRun = "c:windowssystem32windowspowershellv1.0powershell.exe -noninteractive -command `"& '$scriptFilePath'`"";
- $taskToRun
- schtasks /create /tn 'ATest' /ru $userName /rp $userPassword /sc MINUTE /mo 1 /st '00:00' /f /tr $taskToRun;
- # Gets imported but mangles the tr so instead of
- $taskToRun = 'c:windowssystem32windowspowershellv1.0powershell.exe -noninteractive -command "& ''' + $scriptFilePath + '''"';
- $taskToRun
- schtasks /create /tn 'ATest' /ru $userName /rp $userPassword /sc MINUTE /mo 1 /st '00:00' /f /tr $taskToRun;
- $taskToRun = "c:windowssystem32windowspowershellv1.0powershell.exe -noninteractive -file ""$scriptFilePath"""
- $taskToRun = "c:windowssystem32windowspowershellv1.0powershell.exe -noninteractive -file '$scriptFilePath'";
Add Comment
Please, Sign In to add comment