ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Robocopy script not running from task scheduler

    IT Discussion
    windows 2012 r2 robocopy powershell
    7
    22
    4.7k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • RomoR
      Romo
      last edited by

      Ok, so we have a simple robocopy script that copies over a db file from a remote server to the file server. When the script is run manually, directly from powershell it works without trouble but when the script is run from task scheduler it doesn't complete. It just shows as running and it eventually timesout according to the max time set to run in task scheduler. It actually doesn't create the robocopy log file so no idea what is really happening.

      OS is Windows Server 2012R2
      Script:
      robocopy $originDirectory $destinationDirectory /mir /V /log+:C:\folder\script.log

      Security options for the script are set:
      security-options.png

      Trigger is:
      Program: C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe
      Arguments: -Execution Policy Unrestricted -File "C:\folder\script.ps1"
      Start in : C:\folder\

      Share permissions are properly set since the script being manually run works properly unless I am missing something.

      Credentials for the remote share are stored properly in credential manager.

      Any idea what I am missing in order for the script to properly be run from task scheduler

      J 1 Reply Last reply Reply Quote 1
      • J
        JasGot @Romo
        last edited by

        @Romo said in Robocopy script not running from task scheduler:

        Arguments: -Execution Policy Unrestricted -File "C:\folder\script.ps1"

        Is the path to the remote server available to the account the script is running under? ie; the system account or another? You may have to net use the path with credentials in the script. Just my first guess.....

        RomoR 1 Reply Last reply Reply Quote 1
        • RomoR
          Romo @JasGot
          last edited by

          @JasGot Same account currently as the user running the script manually. Also forgot to mention it had been working before without adding net use and the UNC until someone else tried to make a modification.

          J ObsolesceO 2 Replies Last reply Reply Quote 0
          • J
            JasGot @Romo
            last edited by

            @Romo said in Robocopy script not running from task scheduler:

            @JasGot Same account currently as the user running the script manually. Also forgot to mention it had been working before without adding net use and the UNC until someone else tried to make a modification.

            Ah! A helper!

            Must be a syntax error early in the file.

            RomoR 1 Reply Last reply Reply Quote 0
            • RomoR
              Romo @JasGot
              last edited by

              @JasGot In the script file you mean?

              1 Reply Last reply Reply Quote 0
              • RomoR
                Romo
                last edited by

                It does run without trouble when running directly though, so not sure about a syntax error.

                J 1 Reply Last reply Reply Quote 0
                • J
                  JasGot @Romo
                  last edited by

                  @Romo said in Robocopy script not running from task scheduler:

                  It does run without trouble when running directly though, so not sure about a syntax error.

                  Is the server it is running on a DC?

                  Does it fail to run if logged in or not logged in?

                  RomoR 1 Reply Last reply Reply Quote 0
                  • RomoR
                    Romo @JasGot
                    last edited by

                    @JasGot Yes, it is actually the DC server. From task scheduler I have tried it logged in as the same account that is running the script and from a different user account with the script user not logged in at all.

                    1 Reply Last reply Reply Quote 0
                    • black3dynamiteB
                      black3dynamite
                      last edited by

                      Have you tried using Bypass instead of Unrestricted?

                      RomoR 1 Reply Last reply Reply Quote 0
                      • RomoR
                        Romo @black3dynamite
                        last edited by

                        @black3dynamite Yes =(

                        1 Reply Last reply Reply Quote 0
                        • ObsolesceO
                          Obsolesce @Romo
                          last edited by

                          @Romo said in Robocopy script not running from task scheduler:

                          @JasGot Same account currently as the user running the script manually. Also forgot to mention it had been working before without adding net use and the UNC until someone else tried to make a modification.

                          If it was working before and then stopped working when nothing was changed, that smells like a Windows update messed things up.

                          jmooreJ RomoR 2 Replies Last reply Reply Quote 1
                          • jmooreJ
                            jmoore @Obsolesce
                            last edited by

                            @Obsolesce Would have to agree there. I do this on many machines here and at first glance it sure looks right. I;m not running from a dc though

                            1 Reply Last reply Reply Quote 0
                            • RomoR
                              Romo @Obsolesce
                              last edited by

                              @Obsolesce said in Robocopy script not running from task scheduler:

                              @Romo said in Robocopy script not running from task scheduler:

                              @JasGot Same account currently as the user running the script manually. Also forgot to mention it had been working before without adding net use and the UNC until someone else tried to make a modification.

                              If it was working before and then stopped working when nothing was changed, that smells like a Windows update messed things up.

                              Yeah, it could be a possibility. Something in the task was changed though but not sure exactly what was changed. We were told a couple of days after it had stopped working.

                              What I really find strange is that the scripts works just fine when manually run. We must be missing something somewhere that makes the script fail on task scheduler.

                              Maybe when running through task scheduler it can't access the credentials in Credential manager until something is executed beforehand??

                              ObsolesceO 1 Reply Last reply Reply Quote 0
                              • RomoR
                                Romo
                                last edited by

                                Ok finally something new, apparently something is wrong with the destination folder as I am getting:
                                Screenshot from 2019-04-02 19-00-38.png

                                So through Task scheduler it cant write to the destination folder for some reason.

                                EddieJenningsE 1 Reply Last reply Reply Quote 0
                                • scottalanmillerS
                                  scottalanmiller
                                  last edited by scottalanmiller

                                  For Google: "ERROR 19 (0x00000013) Accessing Destination Directory. The media is write protected."

                                  1 Reply Last reply Reply Quote 0
                                  • EddieJenningsE
                                    EddieJennings @Romo
                                    last edited by

                                    @Romo said in Robocopy script not running from task scheduler:

                                    Ok finally something new, apparently something is wrong with the destination folder as I am getting:
                                    Screenshot from 2019-04-02 19-00-38.png

                                    So through Task scheduler it cant write to the destination folder for some reason.

                                    Does the destination path have enough storage? If the path is an external drive, make sure it's not showing as read-only in Disk Management.

                                    RomoR 1 Reply Last reply Reply Quote 0
                                    • ObsolesceO
                                      Obsolesce @Romo
                                      last edited by

                                      @Romo said in Robocopy script not running from task scheduler:

                                      Maybe when running through task scheduler it can't access the credentials in Credential manager until something is executed beforehand??

                                      If you are running your script as SYSTEM, the credentials need to be put into Credential Manager as SYSTEM.

                                      For example, use PSEXEC to run powershell as SYSTEM, then you can add credentials to Credentail Manager and call them from PowerShell using the CredentialManager PowerShell module.

                                      jmooreJ RomoR 2 Replies Last reply Reply Quote 1
                                      • jmooreJ
                                        jmoore @Obsolesce
                                        last edited by

                                        @Obsolesce This kind of what I do. I had too many problems with credentials in windows and powershell so I just started psexec within powershell to bypass a lot of that trouble. Works better for me anyway.

                                        ObsolesceO 1 Reply Last reply Reply Quote 0
                                        • ObsolesceO
                                          Obsolesce @jmoore
                                          last edited by Obsolesce

                                          @jmoore said in Robocopy script not running from task scheduler:

                                          @Obsolesce This kind of what I do. I had too many problems with credentials in windows and powershell so I just started psexec within powershell to bypass a lot of that trouble. Works better for me anyway.

                                          I meant that in the scenario that you use a Scheduled Task to run a PowerShell script as SYSTEM... in that case, when it looks for credentials in Credential Manager, itwon't find them, unless you add credentials to Credential Manager AS the SYSTEM account, which means you need to be running PowerShell interactively as SYSTEM.

                                          What I've been doing lately is working with Azure Automation PowerShell Runbooks, which has it's own Credential Manager.... which basically works identically to the CredentialManager PS module. So if you use that you don't even need a Windows box. Also, you can simply have a parameter in your PowerShell Runbook to accept webhook that executes the runbook... which is freakin sweet! It's great for building API flows between Azure/Intune/etc and 3rd party services!

                                          jmooreJ 1 Reply Last reply Reply Quote 0
                                          • jmooreJ
                                            jmoore @Obsolesce
                                            last edited by

                                            @Obsolesce Oh thats interesting. I'm not familiar with it. I will look at that when I get time, thanks.

                                            1 Reply Last reply Reply Quote 0
                                            • 1
                                            • 2
                                            • 1 / 2
                                            • First post
                                              Last post