Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DSC_FSRMQuotaTemplate: compare fails when DifferenceObject is null #44

Open
duanejevon opened this issue Aug 19, 2020 · 0 comments
Open

Comments

@duanejevon
Copy link

Details of the scenario you tried and the problem that is occurring

In our environment, we have FSRM templates that already exist, but no threshold percentages have been defined for the quota template.

Verbose logs showing the problem

PS C:\Scripts> Test-DscConfiguration -Path C:\Scripts\UserHome_FSRMQuota\ -Verbose
VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = TestConfiguration,'className' = MSFT_DSCLocalConfigurationManager,'namespaceNam
e' = root/Microsoft/Windows/DesiredStateConfiguration'.
VERBOSE: An LCM method call arrived from computer MYTESTPC with user sid XXXXXXXXXXXXXXXXXXXXXXXXXXXX.
VERBOSE: [NAFILE008]: LCM:  [ Start  Compare  ]
VERBOSE: [NAFILE008]: LCM:  [ Start  Resource ]  [[FSRMQuotaTemplate]UserHome500MB]
VERBOSE: [NAFILE008]: LCM:  [ Start  Test     ]  [[FSRMQuotaTemplate]UserHome500MB]
VERBOSE: [NAFILE008]:                            [[FSRMQuotaTemplate]UserHome500MB] Test-TargetResource: Testing FSRM Quota Template "ZAF - HOME - 500MB".
Cannot bind argument to parameter 'DifferenceObject' because it is null.
    + CategoryInfo          : InvalidData: (:) [], CimException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.CompareObjectCommand
    + PSComputerName        : MYTESTPC
 
VERBOSE: [NAFILE008]: LCM:  [ End    Test     ]  [[FSRMQuotaTemplate]UserHome500MB] False in 0.0310 seconds.
VERBOSE: [NAFILE008]: LCM:  [ *FAILED*Compare  ]     Completed processing compare operation. The operation returned False.
The PowerShell DSC resource '[FSRMQuotaTemplate]UserHome500MB' with SourceInfo 'C:\Scripts\FSRMUserHomeQuota.ps1::19::9::FSRMQuotaTemplate' threw one or more 
non-terminating errors while running the Test-TargetResource functionality. These errors are logged to the ETW channel called Microsoft-Windows-DSC/Operational. Refer 
to this channel for more details.
    + CategoryInfo          : InvalidOperation: (root/Microsoft/...gurationManager:String) [], CimException
    + FullyQualifiedErrorId : NonTerminatingErrorFromProvider
    + PSComputerName        : MYTESTPC
 
VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 0.183 seconds

Suggested solution to the issue

According to https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/compare-object?view=powershell-7, "If the reference or the difference objects are null ($null), Compare-Object generates a terminating error." This can be worked around by adjusting

-DifferenceObject $quotaTemplate.Threshold.Percentage).Count -ne 0)
to be something like as follows:

   -DifferenceObject @($quotaTemplate.Threshold.Percentage|select-object)).Count -ne 0)

The DSC configuration that is used to reproduce the issue (as detailed as possible)

configuration UserHome_FSRMQuota 
{ 
    param
    (
        [string[]]$NodeName=$env:COMPUTERNAME
    )

    Import-DscResource -Module FSRMDsc

    $Name = 'ZAF - HOME - 500MB'
    $MailTo = '[Source Io Owner Email]'
    $MailCC = '[email protected]'
    $Subject = 'Home [Quota Threshold]% quota threshold exceeded'
    $Body = 'Your HOME drive folder has used [Quota Threshold]% of the space allocated to it on the server. The limit is [Quota Limit MB] MB and [Quota Used MB] has been used.'
    
    Node $NodeName 
    { 

        FSRMQuotaTemplate UserHome500MB 
        { 
            Name = $Name 
            Description = '500 MB Hard Limit for User Home folders (DSC Created)' 
            Ensure = 'Present' 
            Size = 500MB 
            SoftLimit = $False 
            ThresholdPercentages = @( 95, 100 ) 
        } # End of FSRMQuotaTemplate Resource 
 
        FSRMQuotaTemplateAction UserHome500MBEmail95
        { 
            Name = $Name 
            Percentage = 95 
            Ensure = 'Present' 
            Type = 'Email' 
            Subject = $Subject
            Body = $Body
            MailBCC = '' 
            MailCC = $MailCC
            MailTo = $MailTo
            DependsOn = "[FSRMQuotaTemplate]UserHome500MB"
        } # End of FSRMQuotaTemplateAction Resource
 
        FSRMQuotaTemplateAction UserHome500MBEmail100
        { 
            Name = $Name 
            Percentage = 100
            Ensure = 'Present' 
            Type = 'Email' 
            Subject = $Subject
            Body = $Body
            MailBCC = '' 
            MailCC = $MailCC
            MailTo = $MailTo
            DependsOn = "[FSRMQuotaTemplate]UserHome500MB"
        } # End of FSRMQuotaTemplateAction Resource

        FSRMAutoQuota DUsers 
        { 
            Path = 'D:\HOME' 
            Ensure = 'Present' 
            Disabled = $false 
            Template = $Name
        } # End of FSRMAutoQuota Resource 
    } # End of Node 
} # End of Configuration

The operating system the target node is running

OsName               : Microsoft Windows Server 2016 Standard
OsOperatingSystemSKU : StandardServerEdition
OsArchitecture       : 64-bit
WindowsBuildLabEx    : 14393.3808.amd64fre.rs1_release.200707-2105
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

Version and build of PowerShell the target node is running

Name                           Value
----                           -----
PSVersion                      5.1.14393.3471
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.3471
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Version of the DSC module that was used ('dev' if using current dev branch)

Currently using version 2.5.0.

Thanks for the great work on this DSC!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant