how to author custom DSC resource that executes under a different credential

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Don Jones Don Jones 2 weeks ago.

  • Author
    Posts
  • #58364
    Profile photo of vamsee
    vamsee
    Participant

    we know some standard DSC resources that allow them to be run under a different credential than the LCM credentials. The property to do this is "PSDscRunAsCredential"

    Question:- I am authoring a custom DSC resource and i need this capability for this resource Ex:
    function Test-TargetResource {
    [OutputType([bool])]
    param (
    [PSCredential] $credntial,

    )
    try {

    }
    catch {
    return $false
    }
    }

    How do i make sure that the try block and the catch block in the function are executed under the credential passed?

  • #58367
    Profile photo of vamsee
    vamsee
    Participant

    we know some standard DSC resources that allow them to be run under a different credential than the LCM credentials. The property to do this is "PSDscRunAsCredential"

    Question:- I am authoring a custom DSC resource and i need this capability for this resource Ex:
    function Test-TargetResource {
    [OutputType([bool])]
    param (
    [PSCredential] $credntial,
    #some other needed parameters for the resouce
    )
    try {
    #some code that needs to be executed under the passed credential
    }
    catch {
    return $false
    }
    }

    How do i make sure that the try block and the catch block in the function are executed under the credential passed?

  • #58369
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Actually, PSDscRunAsCredential is universal. The LCM will accept it for all resources. You don't have to code this yourself – the LCM just handles it.

You must be logged in to reply to this topic.