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

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?

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?

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.