Documentation Index
Fetch the complete documentation index at: https://tally.wharflab.com/llms.txt
Use this file to discover all available pages before exploring further.
powershell/PSDSCUseIdenticalMandatoryParametersForDSC is a PSScriptAnalyzer diagnostic emitted by tally for PowerShell snippets embedded in
Dockerfiles.
| Property | Value |
|---|
| Severity | Error |
| Category | PSScriptAnalyzer |
| Auto-fix | No |
Description
For script-based DSC resources, if a property is declared with attributes Key or Required in a
MOF file, then it should be present as a mandatory parameter in the corresponding
Get-TargetResource, Set-TargetResource and Test-TargetResource functions.
How
Make sure all the properties with Key or Required attributes have equivalent mandatory
parameters in the Get/Set/Test functions.
Examples
Consider the following mof file.
class WaitForAny : OMI_BaseResource
{
[key, Description("Name of Resource on remote machine")]
string Name;
[required, Description("List of remote machines")]
string NodeName[];
};
Problematic code
function Get-TargetResource
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
$Message
)
}
function Set-TargetResource
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
$Message,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
$Name
)
}
function Test-TargetResource
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
$Message,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
$Name
)
}
Correct code
function Get-TargetResource
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
$Message,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
$Name
)
}
function Set-TargetResource
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
$Message,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
$Name
)
}
function Test-TargetResource
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
$Message,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
$Name
)
}
Source
This rule documentation is adapted from Microsoft’s PSScriptAnalyzer documentation for
DSCUseIdenticalMandatoryParametersForDSC,
licensed under CC BY 4.0.