Guest User

Untitled

a guest
Aug 28th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. Windows schedules task creation issue with powershell
  2. # Create the script file the schedule task will call, note path contains a space
  3. 'set-content c:tempprogram filesa.log "Just done @ $(get-date)"' > 'c:tempprogram filesa.ps1'
  4.  
  5. $scriptFilePath = 'c:tempprogram filesa.ps1';
  6. $userName = read-host 'user name'; # will need log on as batch rights
  7. $userPassword = read-host 'user password';
  8.  
  9. # The following looks good but schtasks args gets messed up so no creation
  10. $taskToRun = "c:windowssystem32windowspowershellv1.0powershell.exe -noninteractive -command `"& '$scriptFilePath'`"";
  11. $taskToRun
  12. schtasks /create /tn 'ATest' /ru $userName /rp $userPassword /sc MINUTE /mo 1 /st '00:00' /f /tr $taskToRun;
  13.  
  14. # Gets imported but mangles the tr so instead of
  15. $taskToRun = 'c:windowssystem32windowspowershellv1.0powershell.exe -noninteractive -command "& ''' + $scriptFilePath + '''"';
  16. $taskToRun
  17. schtasks /create /tn 'ATest' /ru $userName /rp $userPassword /sc MINUTE /mo 1 /st '00:00' /f /tr $taskToRun;
  18.  
  19. $taskToRun = "c:windowssystem32windowspowershellv1.0powershell.exe -noninteractive -file ""$scriptFilePath"""
  20.  
  21. $taskToRun = "c:windowssystem32windowspowershellv1.0powershell.exe -noninteractive -file '$scriptFilePath'";
Add Comment
Please, Sign In to add comment