How to create file on UNC share with DSC?

Welcome Forums DSC (Desired State Configuration) How to create file on UNC share with DSC?

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

 
Senior Moderator
2 months, 1 week ago.

  • Author
    Posts
  • #170521

    Participant
    Topics: 9
    Replies: 21
    Points: 125
    Rank: Participant

    I'm trying to write up a small DSC PoC (vs Ansible), and as part of that, I want to show that DSC can create files on a share.
    I can happily create files locally, but not remotely. (This question follows on from a previous question about copying from a UNC path)
    This is my code Configuration Data:

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

    The Configuration:

    Configuration DSCPOCCreateUNCFile {
    	param (
    		[Parameter()]
    		[PSCredential]$Credential
    	)
    	Import-DscResource -ModuleName PsDesiredStateConfiguration
    	Node 'Server03' {
    		File HelloWorldUNC {
    			DestinationPath = "\\Share\Common\DevOps\PowerShell.DSC.Resources\HelloWorld.txt"
    			Ensure		=	"Present"
    			Type		=	"File"
    			Credential	=	$Credential
    			PSDSCRunAsCredential = $Credential
    		}
    	}
    }

    Then I run:

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

    Which outputs my MOF.

    I then get this When running the DSC Configuration:

    Start-DscConfiguration -Path C:\Temp -Verbose -Wait -Force
    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 Server03 with user sid S-1-5-21-39487305749-1710526943-1674199894-74534.
    VERBOSE: [Server03]: LCM:  [ Start  Set      ]
    VERBOSE: [Server03]: LCM:  [ Start  Resource ]  [[File]HelloWorldUNC]
    VERBOSE: [Server03]: LCM:  [ Start  Test     ]  [[File]HelloWorldUNC]
    VERBOSE: [Server03]:                            [[File]HelloWorldUNC] Access is denied.
    VERBOSE: [Server03]:                            [[File]HelloWorldUNC] The related file/directory is: \\Share\Common\DevOps\PowerShell.DSC.Resources\HelloWorld.txt.
    Access is denied. The related file/directory is: \\Share\Common\DevOps\PowerShell.DSC.Resources\HelloWorld.txt.
        + CategoryInfo          : PermissionDenied: (:) [], CimException
        + FullyQualifiedErrorId : Windows System Error 5
        + PSComputerName        : Server03
    
    VERBOSE: [Server03]: LCM:  [ End    Set      ]
    The SendConfigurationApply function did not succeed.
        + CategoryInfo          : PermissionDenied: (root/Microsoft/...gurationManager:String) [], CimException
        + FullyQualifiedErrorId : MI RESULT 2
        + PSComputerName        : Server03
    
    VERBOSE: Operation 'Invoke CimMethod' complete.
    VERBOSE: Time taken for configuration job to complete is 2.438 seconds
    

    I am entirely stumped, and nothing relevant comes up when I try to google this

    Any ideas what I am doing wrong?
    I can copy from the share fine, and using New-Item from a console is fine too...

  • #170557

    Senior Moderator
    Topics: 8
    Replies: 1085
    Points: 3,650
    Helping Hand
    Rank: Community Hero

    hmmm, never tried creating a file in a network share with credential.

    just for testing, can you add code for mapping that network share using a script resource. Use DependsOn property for File resource to script resource to make sure file resource executes only after script resource.

  • #170566

    Participant
    Topics: 9
    Replies: 21
    Points: 125
    Rank: Participant

    hmmm, never tried creating a file in a network share with credential.

    just for testing, can you add code for mapping that network share using a script resource. Use DependsOn property for File resource to script resource to make sure file resource executes only after script resource.

    Do you think I would have to map a drive to write to a UNC path? That seems a bit odd, no?
    I will try to find how to do that, thanks.

  • #170572

    Senior Moderator
    Topics: 8
    Replies: 1085
    Points: 3,650
    Helping Hand
    Rank: Community Hero

    no, that should not be the solution, but just to nail down the issue.

You must be logged in to reply to this topic.