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

Welcome Forums DSC (Desired State Configuration) 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

 
Keymaster
1 year, 11 months ago.

  • Author
    Posts
  • #58364

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    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

    Keymaster
    Points: 7
    Rank: Member

    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.

The topic ‘how to author custom DSC resource that executes under a different credential’ is closed to new replies.