CertificateDsc
CertificateDsc copied to clipboard
Verbose Messages in Functions in CertificateDsc.Common not being displayed
The verbose preference does not appear to get passed from a *-TargetResource function into and "common" functions that are being called.
An example of this is the calls to Find-CertificateAuthority
in the xCertReq
. The Verbose messages will not be displayed even when *-TargetResource
is called -Verbose.
@johlju reported this on xSQLServer in this issue: https://github.com/PowerShell/xSQLServer/issues/641
Other xCertificate resources have "accidentally" worked around this by building splats from the PSBoundParameters, which will cause the VerbosePreference to be passed through, but a better approach is required.
I'll hold this issue open until we hear some more information around why this behavior is required.
@PlagueHO I've not tried it, but would putting $PSDefaultParameterValues['Verbose'] = $VerbosePreference
at the top of each *-TargetResource method/begin block work?
Hi @iainbrighton - I suspect your solution would work well. My only issue with all solutions so far is that they feel like work arounds to something that I think should behave differently. If -Verbose is set in a call then it should get passed down through any subsequent calls. This does happen except when control is passed to another module (e.g. scope changes).
@PlagueHO I agree that they are all workarounds, but I don't see this being "fixed" outside of PowerShell 6.0 😢. It could just be that I'm a pessimist!
@iainbrighton - haha yes, that is pretty pessimistic, but I tend to agree with you. I am just hopeful that there is something I'm doing wrong somewhere and there is some "official" solution to this.
@Johlju - what do you reckon?
@iainbrighton Might be so, but rather not quick fix this by changing all of the resources. But if we could use the same approach to switch it once in the helper module I would go for that, instead of adding -Verbose to each Write-Verbose in the helper module.
Are we thinking that this is a bug, then maybe we should submit a uservoice for it, to raise the question? If the resource imports the module, is should be in the same scope, and should just pass the VerbosePreference along.
Hi - found this issue from Google. My own helper functions in my own DSC modules are also not printing verbose messages.
Just curious if you have found a better solution to this in the meantime? Or is adding -Verbose to your Write-Verbose calls in the helper module the accepted workaround?
There not a better solution and probably won’t be for MOF resources. Either add -Verbose
to Write-Verbose
calls. Or add -Verbose
to the call of the helper function.