How to copy files from a UNC path using DSC?

Welcome Forums DSC (Desired State Configuration) How to copy files from a UNC path using DSC?

This topic contains 6 replies, has 2 voices, and was last updated by

 
Senior Moderator
1 month, 1 week ago.

  • Author
    Posts
  • #170056

    Participant
    Topics: 8
    Replies: 18
    Points: 108
    Rank: Participant

    I'm trying to write up a small DSC PoC (vs Ansible), and as part of that, I want to copy required DSC Resources to the Windows 2016 server I'm running it on.
    The server doesn't have internet access, so I can't download them directly from the Gallery.
    Configuration Data:

    $ConfigurationData = @{
    	AllNodes = @(
    		@{
    			NodeName="*"
    			PSDscAllowPlainTextPassword=$True
    			PSDscAllowDomainUser=$True
    		}
    	);
    }

    The Configuration:

    Configuration DSCPOCCopyDSCResources {
    	param (
    		[Parameter()]
    		[PSCredential]$Credential
    	)
    	Node 'localhost' {
    		File DirectoryCopy
    		{
    			SourcePath = "\\Share\Common\DevSupport\PowerShell.DSC.Resources"
    			DestinationPath = "C:\Program Files\WindowsPowerShell\Modules"
    			Recurse = $True
    			Type = "Directory"
    			Ensure = "Present"
    			PSDSCRunAsCredential = $Credential
    		}
    	}
    }

    Then I run:

    $Cred = (Get-Credential)
    DSCPOCCopyDSCResources -OutputPath C:\Temp\ -ConfigurationData $ConfigurationData -Credential (Get-Credential)

    I then get this output/error:

    VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' =
    root/Microsoft/Windows/DesiredStateConfiguration'.
    VERBOSE: An LCM method call arrived from computer SRV-PSDSC03 with user sid S-1-5-21-3324808359-1710566943-1674697894-74334.
    VERBOSE: [SRV-PSDSC03]: LCM:  [ Start  Set      ]
    VERBOSE: [SRV-PSDSC03]: LCM:  [ Start  Resource ]  [[File]DirectoryCopy]
    VERBOSE: [SRV-PSDSC03]: LCM:  [ Start  Test     ]  [[File]DirectoryCopy]
    VERBOSE: [SRV-PSDSC03]:                            [[File]DirectoryCopy] Access is denied.
    VERBOSE: [SRV-PSDSC03]:                            [[File]DirectoryCopy] The related file/directory is: \\Share\Common\DevSupport\PowerShell.DSC.Resources.
    VERBOSE: [SRV-PSDSC03]:                            [[File]DirectoryCopy] The path cannot point to the root directory or to the root of a net share.
    VERBOSE: [SRV-PSDSC03]:                            [[File]DirectoryCopy] The related file/directory is: \\Share\Common\DevSupport\PowerShell.DSC.Resources.
    VERBOSE: [SRV-PSDSC03]:                            [[File]DirectoryCopy] SourcePath must be specified if you want to configure the destination directory recursively. Make sure that SourcePath is a directory and that it
    is accessible.
    SourcePath must be specified if you want to configure the destination directory recursively. Make sure that SourcePath is a directory and that it is accessible.
        + CategoryInfo          : InvalidArgument: (:) [], CimException
        + FullyQualifiedErrorId : MI RESULT 4
        + PSComputerName        : localhost

    I first tried Credential instead of PSDSCRunAsCredential, but same error.
    The user sid corresponds to my admin account.

    Any ideas what I am doing wrong?
    I have also tried opening the share in Explorer as well as running Test-Path, both successful...

  • #170059

    Senior Moderator
    Topics: 8
    Replies: 1041
    Points: 3,440
    Helping Hand
    Rank: Community Hero

    you have to pass $Credential to DSCPOCCopyDSCResources while compiling the MOF. You can have a Credential parameter for DSCPOCCopyDSCResources and pass it while compiling the mof.

    The credential used with Start-DSCConfiguration is used to push the configuration, but not to apply the configuration.

  • #170125

    Participant
    Topics: 8
    Replies: 18
    Points: 108
    Rank: Participant

    you have to pass $Credential to DSCPOCCopyDSCResources while compiling the MOF. You can have a Credential parameter for DSCPOCCopyDSCResources and pass it while compiling the mof.

    The credential used with Start-DSCConfiguration is used to push the configuration, but not to apply the configuration.

    Thanks, I overlooked that. My code in the OP has been changed t show what it is now, and now I sadly get a different error:

    PSDesiredStateConfiguration\Configuration : System.InvalidOperationException error processing property 'PSDSCRunAsCredential' OF TYPE 'File': Converting and storing encrypted passwords as plain text is not recommended. For more
    information on securing credentials in MOF file, please refer to MSDN blog: http://go.microsoft.com/fwlink/?LinkId=393729
    At line:32 char:3
    +   File
    At line:25 char:1
    + Configuration DSCPOCCopyDSCResources {
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [Write-Error], InvalidOperationException
        + FullyQualifiedErrorId : FailToProcessProperty,Configuration
    

    And no MOF is generated.

  • #170137

    Senior Moderator
    Topics: 8
    Replies: 1041
    Points: 3,440
    Helping Hand
    Rank: Community Hero
  • #170266

    Participant
    Topics: 8
    Replies: 18
    Points: 108
    Rank: Participant
  • #170416

    Participant
    Topics: 8
    Replies: 18
    Points: 108
    Rank: Participant

    So, it turns out that the real problem was using

    NodeName="*"

    instead of

    NodeName="localhost"

    in my $ConfigurationData.
    Changing that so my $ConfigurationData now reads like this, fixed it:

    $ConfigurationData = @{
    	AllNodes = @(
    		@{
    			NodeName="localhost"
    			PSDscAllowPlainTextPassword=$True
    			PSDscAllowDomainUser=$True
    		}
    	)
    }
    

    However!
    I now have a similar struggle, in that I can't create a new file on a share -__-
    Super annoying, and tempted to make a new post...

  • #170425

    Senior Moderator
    Topics: 8
    Replies: 1041
    Points: 3,440
    Helping Hand
    Rank: Community Hero

    Always welcome,you can make a new post with the new issue...

You must be logged in to reply to this topic.