Robocopy not working

This topic contains 7 replies, has 4 voices, and was last updated by Profile photo of Aravinda Cat Aravinda Cat 1 year, 2 months ago.

  • Author
    Posts
  • #29913
    Profile photo of Aravinda Cat
    Aravinda Cat
    Participant

    Hi Team,

    I am using Robocopy command to copy some files/directory from a pullserver to target node in DSC. When I run the same command in powershell it works fine, but when I am using the same in Script resource , it gives me Access Denied error.(I tried using xRobocopy module, but got the same error).

    All other DSC scripts running fine with the same credential(Even some file resource written to copy some file also work fine).Here is the robocopy command

    ROBOCOPY.exe "\\$PullServer\d`$\xxxxxxx" "D:\xxxxx" /DCOPY:T /MIR /v /log:D:\logcopy.txt

    Any suggestion would be much appreciated.

    Thanks,
    Aravinda

  • #29919
    Profile photo of Daniel Krebs
    Daniel Krebs
    Participant

    Do you have WMF v4 or v5 Production Preview installed on your DSC node?

  • #29923
    Profile photo of Daniel Krebs
    Daniel Krebs
    Participant

    If you are using WMF v5 Production Preview you will need to set PSDSCRunAsCredential of your Script resource.

    configuration Example
    {
        param
        (
            [Paramater(Mandatory)]
            [PSCredential]
            $AdminCredential
        )
    
        Script Test
        {
            GetScript = {}
            SetScript = {}
            TestScript = {}
            PsDscRunAsCredential = $AdminCredential
        }
    }
    

    Similar to examples on below pages:
    http://blogs.msdn.com/b/powershell/archive/2015/07/06/validate-powershell-dsc-runascredential.aspx
    https://github.com/PowerShell/xRobocopy

  • #30020
    Profile photo of Aravinda Cat
    Aravinda Cat
    Participant

    Hi Daniel,

    Currently I am on WMF v4 and I am already using Admin account to run this script, but it throws a Access Denied error 5.

    The real problem is the same command works fine powershell window opened in the same Admin credential, but it does not work in DSC

    Here is the DSC script repository:

    Script copyRepository
    {

    GetScript = {
    #Do Nothing
    }

    SetScript ={
    C:\Windows\System32\Robocopy.exe "\\xxxxxxx\xxxServerxxxx" "D:\xxxx" /DCOPY:T /MIR /v /log:D:\logcopy.txt
    }

    TestScript = {
    $false
    }
    Credential = $cred

    }

    In event viewer Robocopy doesn't throw any error, it simply gets executed correctly only the error comes in log.
    So, What might be the issue with Robocopy not working in DSC for a credential , but works fine in powershell with same credential?

    Thanks,
    Aravinda

  • #30023
    Profile photo of Don Jones
    Don Jones
    Keymaster

    The LCM runs your configurations as System, not as Admin. So when you're testing in the console, that's not the same account that the LCM would use.

  • #30025
    Profile photo of Aravinda Cat
    Aravinda Cat
    Participant

    Hi Don,

    I checked with the process monitor for both the powershell and DSC in the server. The process for Robocopy is run by the same Admin credential provided.

    While opening the powershell window, I am opening it explicitly with the Admin credential and for DSC execution I am providing Credential parameter in Script resource.

    Thanks,
    Aravinda

  • #30808
    Profile photo of Tony Wainwright
    Tony Wainwright
    Participant

    Hi Aravinda,

    My experience with robocopy is that it doesn't play well with drive letters as source or destination in scripts. Try using UNC paths:

    ROBOCOPY \\Server1\reports \\Server2\backup
  • #31910
    Profile photo of Aravinda Cat
    Aravinda Cat
    Participant

    Hi Tony,

    I tried this UNC path also, but looks like it throws the same Access Denied error for this when run using ScriptResource, but if I run the same from powershell console it works fine.

    I also tried giving full permission to a credential for both folders, but nothing clicked.

    Did anybody face the same issue with Robocopy and please let me know if the robocopy is working for anybody in DSC.

    Thanks,
    Aravinda

You must be logged in to reply to this topic.