CR for Log Enabling

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Ryan Young Ryan Young 2 years ago.

  • Author
    Posts
  • #21032
    Profile photo of Ryan Young
    Ryan Young
    Participant

    Hello, So after finding the xWinEvent resource I'm working on a composite resource to get this out. Here's what I've got:

    Configuration rDSCLogging
    {
    	Param(
    	[Parameter(Mandatory = $true)]
    	[string]$Logname,
    
    	[Parameter(Mandatory = $true)]
    	[bool]$setstatus
    	)
    	
    	Import-DscResource -module xWinEventLog
    	
    	$loghalf = "Microsoft-Windows-WMI-Activity/"
    	{
    		xWinEventLog WMILog
    		{
    			Logname = $loghalf + $LogName
    			IsEnabled = $setstatus
    			Logmode = "Circular"
    			MaximumSizeInBytes = 5mb
    		}
    	}
    }
    

    and I am trying to call this resource like so in my main configuration:

     
    Configuration SQLinstall 
    {
        Import-DscResource -name *
     
        Node $allnodes.where({$_.NodeRole -eq "SQL"}).NodeGuid {
            rDSCLogging EnableAnalyticSQL {
                Logname = "Analytic"
                setstatus = $enabled }
                  
            rdsclogging EnableDebugSQL {
                Logname = "Debug"
                setstatus = $enabled }    
     }             
    } 

    Powershell is giving me this error output, likely because I am still newb to paramaters:

    SQLInstall -ConfigurationData $AllServerConfigData -outpath "C:\contoso\WorkDir"
    
    PSDesiredStateConfiguration\Node : Cannot convert value "" to type "System.Boolean". Boolean parameters accept only Boolean values and numbers, such as $True, $False, 1 or 
    0.
    At line:95 char:5
    +     Node $allnodes.where({$_.NodeRole -eq "SQL"}).NodeGuid {
    +     ~~~~
        + CategoryInfo          : InvalidArgument: (:) [PSDesiredStateConfiguration\node], ParentContainsErrorRecordException
        + FullyQualifiedErrorId : InvalidCastExceptionUnsupportedParameterType,PSDesiredStateConfiguration\node
     
    PSDesiredStateConfiguration\Node : Cannot convert value "" to type "System.Boolean". Boolean parameters accept only Boolean values and numbers, such as $True, $False, 1 or 
    0.
    At line:95 char:5
    +     Node $allnodes.where({$_.NodeRole -eq "SQL"}).NodeGuid {
    +     ~~~~
        + CategoryInfo          : InvalidArgument: (:) [PSDesiredStateConfiguration\node], ParentContainsErrorRecordException
        + FullyQualifiedErrorId : InvalidCastExceptionUnsupportedParameterType,PSDesiredStateConfiguration\node
     
    PSDesiredStateConfiguration\Node : Cannot convert value "" to type "System.Boolean". Boolean parameters accept only Boolean values and numbers, such as $True, $False, 1 or 
    0.
    At line:95 char:5
    +     Node $allnodes.where({$_.NodeRole -eq "SQL"}).NodeGuid {
    +     ~~~~
        + CategoryInfo          : InvalidArgument: (:) [PSDesiredStateConfiguration\node], ParentContainsErrorRecordException
        + FullyQualifiedErrorId : InvalidCastExceptionUnsupportedParameterType,PSDesiredStateConfiguration\node
     
    Errors occurred while processing configuration 'SQLinstall'.
    At C:\Windows\system32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psm1:2223 char:5
    +     throw $errorRecord
    +     ~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (SQLinstall:String) [], InvalidOperationException
        + FullyQualifiedErrorId : FailToProcessConfiguration
    

    Configuration data is populated with computers from AD, and is proven to work with other configs.

  • #21041
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    What is in your $enabled variable? That's the only place I can see that you might be running into trouble with a conversion to Boolean.

  • #21046
    Profile photo of Ryan Young
    Ryan Young
    Participant

    Thanks as always for the reply Dave! The situation has changed just a bit, now the script works IF I specify a node in the configuration. If I do not, then when I try to use $allnodes.Where({$_.NodeRole -eq "sql}).nodeguid tied into -configurationdata the command is taken but no MOFs are generated.

    Updated composite resource: (DSCLogging.schema.psm1)

    Configuration rDSCLogging
    {
    	Param (
    		[Parameter(Mandatory = $true)]
    		[validateset('Analytic', 'Operational', 'Debug')]
    		[string]$Logname,
    		
    		[Parameter(Mandatory = $true)]
    		[string]$setstatus
    	)
    	
    	switch ($setstatus)
    	{
    		'Enable' { $true }
    		'Enabled' { $true }
    		'Disable' { $false }
    		'Disabled' { $false }
    		default { $false }
    	}
    	Import-DscResource -module xWinEventLog
    	
    	$loghalf = "Microsoft-Windows-WMI-Activity/"
    #	node Localhost
    	{
    		xWinEventLog WMILog
    		{
    			Logname = $loghalf + $LogName
    			IsEnabled = $setstatus
    			Logmode = "Circular"
    			MaximumSizeInBytes = 5mb
    		}
    	}
    }

    Updated masterconfig entry:

    Configuration SQLinstall 
    {
        Import-DscResource -name *
     
        Node $allnodes.where({$_.NodeRole -eq "SQL"}).NodeGuid {
            rDSCLogging EnableAnalyticSQL {
                Logname = "Analytic"
                setstatus = "Enabled" }
                  
            rdsclogging EnableDebugSQL {
                Logname = "Debug"
                setstatus = "Enabled" }    
     }             
    }
    
    SQLInstall -ConfigurationData $AllServerConfigData -outpath "C:\Contoso\WorkDir"
    

    Isn't it strange that it'll make me a perfect MOF if I specify the node but I can't feed configurationdata to it?

You must be logged in to reply to this topic.