Robocopy not working

Welcome Forums DSC (Desired State Configuration) Robocopy not working

This topic contains 7 replies, has 4 voices, and was last updated by

 
Participant
3 years, 1 month ago.

  • Author
    Posts
  • #29913

    Participant
    Points: 0
    Rank: Member

    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

    Moderator
    Points: 24
    Team Member
    Rank: Member

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

  • #29923

    Moderator
    Points: 24
    Team Member
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    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

    Keymaster
    Points: 1,704
    Helping HandTeam Member
    Rank: Community Hero

    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

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    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

The topic ‘Robocopy not working’ is closed to new replies.