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

Error compiling configuration on Windows Server 2012R2 #434

Open
sabanichev opened this issue Jul 11, 2019 · 2 comments
Open

Error compiling configuration on Windows Server 2012R2 #434

sabanichev opened this issue Jul 11, 2019 · 2 comments

Comments

@sabanichev
Copy link

Based on documentation, trying to compile the following configuration on the following environment
OS: Windows Server2012R2
PowerStig version: 3.2.0

configuration Example
{
    param
    (
        [parameter()]
        [string]$NodeName = 'localhost'
    )

    Import-DscResource -ModuleName PowerStig
    
    Node $NodeName
    {
        WindowsServer BaseLine
        {
            OsVersion   = '2012R2'
            OsRole      = 'MS'
            StigVersion = '2.12'
        }
    }
}

Example -OutputPath C:\dev

and see the following error:

PSDesiredStateConfiguration\Configuration : The property '' cannot be found on this object. Verify that the property exists and can be set.
At C:\Program Files\WindowsPowerShell\Modules\PowerSTIG\3.2.0\DSCResources\WindowsServer\WindowsServer.schema.psm1:39 char:1
+ Configuration WindowsServer
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Configuration], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : PropertyAssignmentException,Configuration
 
Compilation errors occurred while processing configuration 'Example'. Please review the errors reported in error stream and modify your configuration code appropriately.
At C:\Windows\system32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psm1:3917 char:5
+     throw $ErrorRecord
+     ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Example:String) [], InvalidOperationException
    + FullyQualifiedErrorId : FailToProcessConfiguration

With PowerStig module version 2.4.0.0 this example working as expected on Windows Server 2012R2

Also, version 3.2.0 could be compiled successfully to mof file on Windows 10

@jcwalker
Copy link
Member

@sabanichev can you provide the link where you got that example. I can't find that example any place in the wiki. However, try specifying a forest and domain name like in this example

@dubswalker1
Copy link

dubswalker1 commented Sep 4, 2019

I've seen this same issue on 2012R2, running the WindowsServer example above and others, like https://github.com/Microsoft/PowerStig/wiki/Office (one change needed here was to update the PowerStig ModuleVersion to 3.3.0).

After some debugging, there appears to be an issue in Module\Rule\Rule.psm1 - in the hidden GetOverrideValue() function. The call to [regex]::Matches returns a malformed Groups value which will not provide the right $exceptionProperty value.

I was running this same example on Windows Server 2012 R2 (Powershell version 5.1.14409) and Windows 10 (Powershell version 5.1.16299) side-by-side and it was clearly the return value from the Matches expression which was different and the source of the problem on WS2012R2.
The problematic expression:
[regex]::Matches(
(Get-Content -path $baseclassPath -raw), $exceptionPropertyTag)

I made some changes to Rule.psm1 and was able to get past this issue
Original code snippet:

$exceptionProperty = [regex]::Matches(
        (Get-Content -path $baseclassPath -raw), $exceptionPropertyTag
        ).Groups.Where( {$_.Name -eq 'ExceptionValue'}).Value

Changed to:

$content = Get-Content -Path $baseclassPath -Raw
$exceptionProperty = 'No Rule Exception Found'
if ($content -match $exceptionPropertyTag)
{
     $exceptionProperty = $Matches.ExceptionValue
}

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

3 participants