Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #144 from X-Guardian/PsScriptAnalyzer-Fix
Browse files Browse the repository at this point in the history
Fix Custom DSC Resource Kit PSSA Rule Failures
  • Loading branch information
mhendric authored Apr 26, 2019
2 parents 5294226 + db25196 commit ced91be
Show file tree
Hide file tree
Showing 11 changed files with 236 additions and 17 deletions.
32 changes: 21 additions & 11 deletions DscResources/MSFT_EnvironmentResource/MSFT_EnvironmentResource.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function Get-TargetResource
[String]
$Name,

[Parameter()]
[ValidateSet('Process', 'Machine')]
[ValidateNotNullOrEmpty()]
[String[]]
Expand All @@ -47,7 +48,7 @@ function Get-TargetResource
$valueToReturn = $null

if ($Target -contains 'Machine')
{
{
$environmentVaraible = Get-EnvironmentVariableWithoutExpanding -Name $Name -ErrorAction 'SilentlyContinue'

if ($null -ne $environmentVaraible)
Expand All @@ -67,9 +68,9 @@ function Get-TargetResource
}

if ($null -eq $valueToReturn)
{
{
Write-Verbose -Message ($script:localizedData.EnvVarNotFound -f $Name)
}
}
else
{
Write-Verbose -Message ($script:localizedData.EnvVarFound -f $Name, $valueToReturn)
Expand Down Expand Up @@ -122,17 +123,21 @@ function Set-TargetResource
[String]
$Name,

[Parameter()]
[ValidateNotNull()]
[String]
$Value = [String]::Empty,

[Parameter()]
[ValidateSet('Present', 'Absent')]
[String]
$Ensure = 'Present',

[Parameter()]
[Boolean]
$Path = $false,

[Parameter()]
[ValidateSet('Process', 'Machine')]
[ValidateNotNullOrEmpty()]
[String[]]
Expand Down Expand Up @@ -192,7 +197,6 @@ function Set-TargetResource

if ($createMachineVariable -and $createProcessVariable)
{

if (-not $valueSpecified)
{
<#
Expand Down Expand Up @@ -430,17 +434,21 @@ function Test-TargetResource
[String]
$Name,

[Parameter()]
[ValidateNotNull()]
[String]
$Value,

[Parameter()]
[ValidateSet('Present', 'Absent')]
[String]
$Ensure = 'Present',

[Parameter()]
[Boolean]
$Path = $false,

[Parameter()]
[ValidateSet('Process', 'Machine')]
[ValidateNotNullOrEmpty()]
[String[]]
Expand Down Expand Up @@ -525,9 +533,9 @@ function Test-TargetResource

# If the control reaches here, the expected environment variable exists, it is a path variable and a $Value is specified to test against
if ($Ensure -eq 'Present')
{
{
if ($checkMachineTarget)
{
{
if (-not (Test-PathsInValue -ExistingPaths $currentValueFromMachine -QueryPaths $Value -FindCriteria 'All'))
{
# If the control reached here some part of the specified path ($Value) was not found in the existing variable, return failure
Expand Down Expand Up @@ -693,8 +701,8 @@ function Add-PathsToValue
$currentPaths = $CurrentValue -split ';'
$newPaths = $NewValue -split ';'

foreach ($path in $newPaths)
{
foreach ($path in $newPaths)
{
if ($currentPaths -notcontains $path)
{
<#
Expand All @@ -703,8 +711,8 @@ function Add-PathsToValue
#>

$finalValue += ($path + ';')
}
}
}
}

# Remove any extraneous ';' at the end (and potentially start - as a side-effect) of the value to be set
return $finalValue.Trim(';')
Expand Down Expand Up @@ -803,6 +811,7 @@ function Set-EnvironmentVariable
[String]
$Name,

[Parameter()]
[String]
$Value,

Expand Down Expand Up @@ -931,6 +940,7 @@ function Set-ProcessEnvironmentVariable
[String]
$Name,

[Parameter()]
[String]
$Value = [String]::Empty
)
Expand Down Expand Up @@ -1023,7 +1033,7 @@ function Test-PathsInValue
'Any'
{
foreach ($queryPath in $queryPathList)
{
{
if ($existingPathList -contains $queryPath)
{
# Found this $queryPath in the existing paths, return $true
Expand Down
45 changes: 45 additions & 0 deletions DscResources/MSFT_GroupResource/MSFT_GroupResource.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ function Get-TargetResource
[String]
$GroupName,

[Parameter()]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
$Credential
Expand Down Expand Up @@ -188,22 +189,28 @@ function Set-TargetResource
[String]
$GroupName,

[Parameter()]
[ValidateSet('Present', 'Absent')]
[String]
$Ensure = 'Present',

[Parameter()]
[String]
$Description,

[Parameter()]
[String[]]
$Members,

[Parameter()]
[String[]]
$MembersToInclude,

[Parameter()]
[String[]]
$MembersToExclude,

[Parameter()]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
Expand Down Expand Up @@ -286,22 +293,28 @@ function Test-TargetResource
[String]
$GroupName,

[Parameter()]
[ValidateSet('Present', 'Absent')]
[String]
$Ensure = 'Present',

[Parameter()]
[String]
$Description,

[Parameter()]
[String[]]
$Members,

[Parameter()]
[String[]]
$MembersToInclude,

[Parameter()]
[String[]]
$MembersToExclude,

[Parameter()]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
Expand Down Expand Up @@ -343,6 +356,7 @@ function Get-TargetResourceOnFullSKU
[String]
$GroupName,

[Parameter()]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
$Credential
Expand Down Expand Up @@ -411,6 +425,7 @@ function Get-TargetResourceOnNanoServer
[String]
$GroupName,

[Parameter()]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
$Credential
Expand Down Expand Up @@ -508,22 +523,28 @@ function Set-TargetResourceOnFullSKU
[String]
$GroupName,

[Parameter()]
[ValidateSet('Present', 'Absent')]
[String]
$Ensure = 'Present',

[Parameter()]
[String]
$Description,

[Parameter()]
[String[]]
$Members,

[Parameter()]
[String[]]
$MembersToInclude,

[Parameter()]
[String[]]
$MembersToExclude,

[Parameter()]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
Expand Down Expand Up @@ -859,22 +880,28 @@ function Set-TargetResourceOnNanoServer
[String]
$GroupName,

[Parameter()]
[ValidateSet('Present', 'Absent')]
[String]
$Ensure = 'Present',

[Parameter()]
[String]
$Description,

[Parameter()]
[String[]]
$Members,

[Parameter()]
[String[]]
$MembersToInclude,

[Parameter()]
[String[]]
$MembersToExclude,

[Parameter()]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
Expand Down Expand Up @@ -1092,22 +1119,28 @@ function Test-TargetResourceOnFullSKU
[String]
$GroupName,

[Parameter()]
[ValidateSet('Present', 'Absent')]
[String]
$Ensure = 'Present',

[Parameter()]
[String]
$Description,

[Parameter()]
[String[]]
$Members,

[Parameter()]
[String[]]
$MembersToInclude,

[Parameter()]
[String[]]
$MembersToExclude,

[Parameter()]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
Expand Down Expand Up @@ -1353,22 +1386,28 @@ function Test-TargetResourceOnNanoServer
[String]
$GroupName,

[Parameter()]
[ValidateSet('Present', 'Absent')]
[String]
$Ensure = 'Present',

[Parameter()]
[String]
$Description,

[Parameter()]
[String[]]
$Members,

[Parameter()]
[String[]]
$MembersToInclude,

[Parameter()]
[String[]]
$MembersToExclude,

[Parameter()]
[ValidateNotNullOrEmpty()]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
Expand Down Expand Up @@ -1571,6 +1610,7 @@ function Get-MembersOnFullSKU
[AllowEmptyCollection()]
$Disposables,

[Parameter()]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
$Credential
Expand Down Expand Up @@ -1656,6 +1696,7 @@ function Get-MembersAsPrincipalsList
[AllowEmptyCollection()]
$Disposables,

[Parameter()]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
$Credential
Expand Down Expand Up @@ -1833,6 +1874,7 @@ function ConvertTo-UniquePrincipalsList
[AllowEmptyCollection()]
$Disposables,

[Parameter()]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
$Credential
Expand Down Expand Up @@ -1922,6 +1964,7 @@ function ConvertTo-Principal
[AllowEmptyCollection()]
$Disposables,

[Parameter()]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
$Credential
Expand Down Expand Up @@ -2061,6 +2104,7 @@ function Get-PrincipalContext
[String]
$Scope,

[Parameter()]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
$Credential,
Expand Down Expand Up @@ -2329,6 +2373,7 @@ function Find-Principal
[String]
$IdentityValue,

[Parameter()]
[System.DirectoryServices.AccountManagement.IdentityType]
$IdentityType
)
Expand Down
Loading

0 comments on commit ced91be

Please sign in to comment.