PowerShell DSC资源找不到配置关键字

PowerShell DSC资源找不到配置关键字,powershell,configuration,dsc,Powershell,Configuration,Dsc,我正在为我们的开发机器进行DSC配置设置。我遇到的要么是我在使用复合资源时出错,要么是我看不到的东西 我可以毫无问题地运行DevMachineConfig.ps1,但是当我使用DeveloperMachine-ConfigurationData$ConfigurationData创建MOF文件时,出现以下错误: PSDesiredStateConfiguration\Configuration : The argument is null. Provide a valid value for

我正在为我们的开发机器进行DSC配置设置。我遇到的要么是我在使用复合资源时出错,要么是我看不到的东西

我可以毫无问题地运行DevMachineConfig.ps1,但是当我使用
DeveloperMachine-ConfigurationData$ConfigurationData
创建MOF文件时,出现以下错误:

PSDesiredStateConfiguration\Configuration : The argument is null. Provide a valid value for 
the argument, and then try running the command again.
At C:\Program Files\WindowsPowerShell\Modules\DeveloperConfig\DSCResources\CreateDomainController\CreateDomainController.schema.psm1:1 char:1
+ Configuration CreateDomainController
+ ~~~~~~~~~~~~~
+ CategoryInfo          : MetadataError: (:) [Configuration], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ArgumentIsNull,Configuration
我只是不清楚为什么在
Configuration
关键字上出现空值,因为这似乎是内置的DSC

所以我的问题是这是我的错误还是DSC的错误

以下是文件和相关信息 我的“项目”布局:

*模块文件夹连接到$env:ProgramFiles\WindowsPowershell\Modules

DevMachineConfig.ps1 GetDscResources.schema.psm1 CreateDomainController.schema.psm1
配置CreateDomainController
{
Param(
[string]$DomainName=“dev.loc”,
[参数(强制性)]
[哈希表[]]$DomainUsers=$null
)
导入模块-名称ActiveDirectory
导入DscResource-ModuleName xActiveDirectory
$password=converttosecurestring“password1!!”-AsPlainText-Force
$credentials=新对象System.Management.Automation.PSCredential(“管理员”,$password)
xADDomain开发域
{
域名=$DomainName
DomainAdministratorCredential=$credentials
SafemodeAdministratorPassword=$credentials
}
xWaitForADDomain ADForestWait
{
域名=$DomainName
DomainUserCredential=$credentials
RetryCount=20
重试间隔=30
DependsOn=“[xADDomain]开发域”
}
foreach($DomainUsers中的domainUser)
{
xADUser$domainUser.Name
{
域名=$DomainName
DomainAdministratorCredential=$credentials
用户名=$domainUser.Name
密码=$credentials
确保=“在场”
DependsOn=“[XWaitForAddDomain]ADForestWait”
}
if($domainUser.DomainAdmin-eq$True)
{
添加ADPrincipalGroupMembership-Identity$adminUser.Name-MemberOf“域管理员”
}
if($domainUser.DelegateAccount-eq$True)
{
$rootDse=[ADSI]“LDAP://rootDse”
$principal=新对象Security.principal.NTAccount(“DEV\$($domainUser.Name)”)
DSACLS“$($rootDse.defaultNamingContext)”/G“$($principal):CA;复制目录更改”
DSACLS“$($rootDse.configurationNamingContext)”/G“$($principal):CA;复制目录更改”
}
}
}
这更像是一个Powershell问题,而不是DSC问题。您有一个带有默认值的强制参数。你应该选择其中一个


强制意味着必须提供参数。默认值实际上应该与
强制=$false
一起使用,因为这样它的行为更有意义(如果调用方不提供值,则使用此值)。

我正在移动设备上查看此值,无法真正测试它,但我想知道
[哈希表[]]
是否不可为空?如果默认值改为
@()
,会怎么样?因此,这比我想象的要容易。原来我在调用一个未定义的变量(
$adminUser
)。结果显示错误报告不正确。你的提示通过检查我的变量帮助我朝着正确的方向前进,我终于注意到了。很高兴这有帮助,@Jason。我知道这是一个较旧的线程,但我发现帮助我找到类似错误的是查看$error变量。它将具有比构建mof文件时显示的一般错误更详细的信息。希望这对其他人有帮助。
\DevMachineConfig.ps1
\Modules\DeveloperConfig\DeveloperConfg.psd1
\Modules\DeveloperConfig\DSCResources\GetDscResources\GetDscResources.schema.psm1
\Modules\DeveloperConfig\DSCResources\CreateDomainController\CreateDomainController.schema.psm1
$ConfigurationData = @{
AllNodes = @(
    @{ 
        NodeName = "localhost"; 
        DomainName = "dev.loc";
        PSDscAllowPlainTextPassword = $true;            
        DomainUsers = @(
            @{ Name = 'web-app'; DomainAdmin = $False }               
        );
     }
)
}

Configuration DeveloperMachine 
{
   $installPassword = ConvertTo-SecureString "password!!" -AsPlainText -Force
   $credentials = New-Object 
             System.Management.Automation.PSCredential("deltaadmin" $installPassword)

Import-DscResource -ModuleName DeveloperConfig, xSystemSecurity

Node "localhost"
{
    LocalConfigurationManager 
    {
        DebugMode = "All"
        ActionAfterReboot = "ContinueConfiguration"
    }

    GetDscResources DSCResources { }

    CreateDomainController DevDomain {
        DomainName = $Node.DomainName
        DomainUsers = $Node.DomainUsers
        DependsOn = "[SetWindowsFeatures]Features"
    }
}
Configuration GetDscResources 
{
    param(
        [string] $WorkingDir = "c:\temp\dsc\", 
        [string] $DownloadUrl = "https://gallery.technet.microsoft.com/scriptcenter/DSC-Resource-Kit-All-c449312d/file/131371/1/DSC%20Resource%20Kit%20Wave%209%2012172014.zip"
    )

    $archivePath = Join-Path $WorkingDir "dsc-wave9.zip"
    $resourcesPath = Join-Path $WorkingDir "All Resources"
    $powerShellModule = Join-Path $env:ProgramFiles "WindowsPowerShell\Modules"

    File DeltaDscFolder {
        Ensure = "Present"        
        Type = "Directory"
        DestinationPath = $WorkingDir
    }

    Script DownloadDscResources 
    {
        TestScript = {
            Write-Verbose -Verbose "Checking to see if the path [$using:WorkingDir] exists"
            Write-Verbose -Verbose "Found the Path: $(Test-Path $using:WorkingDir)"
            return !(Test-Path $using:WorkingDir)
        }
        GetScript = { 
            if((Test-Path $(Join-Path $using:powerShellModule "xActiveDirectory")))
            {
                $result = "DSC Resources have been downloaded."
            } else {
                $result = "DSC Resources have not been downloaded."
            }

            return @{ 
                Result = $result
                GetScript = $GetScript
                SetScript = $SetScript
                TestScript = $TestScript
            }
        }
        SetScript = {
            Write-Verbose -Verbose "Downloading the wave9 resources from $using:DownloadUrl to $using:archivePath"
            (New-Object System.Net.WebClient).DownloadFile($using:DownloadUrl, $using:archivePath)
            Write-Verbose -Verbose "Download complete"
        }
        DependsOn = "[File]DeltaDscFolder"
    }

    Archive DscResourceWave9 {
        Destination = $WorkingDir
        Path = $archivePath
        Ensure = "Present"
        DependsOn = "[Script]DownloadDscResources"
    }

    File MoveDscTo {
        Ensure = "Present"
        Type = "Directory"
        Recurse = $true
        SourcePath = $resourcesPath
        DestinationPath = $powerShellModule
        DependsOn = "[Archive]DscResourceWave9"
    }
}
Configuration CreateDomainController 
{
    Param(
        [string] $DomainName = "dev.loc",
        [Parameter(Mandatory)]
        [Hashtable[]] $DomainUsers = $null
    )

    Import-Module -Name ActiveDirectory 
    Import-DscResource -ModuleName xActiveDirectory

    $password = ConvertTo-SecureString "password1!!" -AsPlainText -Force
    $credentials = New-Object System.Management.Automation.PSCredential("admin", $password)

        xADDomain DevelopmentDomain
        {
            DomainName = $DomainName
            DomainAdministratorCredential = $credentials
            SafemodeAdministratorPassword = $credentials
        }

        xWaitForADDomain ADForestWait
        {
            DomainName = $DomainName
            DomainUserCredential = $credentials
            RetryCount = 20
            RetryIntervalSec = 30
            DependsOn = "[xADDomain]DevelopmentDomain"
        }

        <#
            Generate the domain users.
        #>

        foreach($domainUser in $DomainUsers) 
        {
            xADUser $domainUser.Name
            {
                DomainName = $DomainName
                DomainAdministratorCredential = $credentials
                UserName = $domainUser.Name
                Password = $credentials
                Ensure = "Present"
                DependsOn = "[xWaitForADDomain]ADForestWait"            
            }

            if($domainUser.DomainAdmin -eq $True)
            {
                Add-ADPrincipalGroupMembership -Identity $adminUser.Name -MemberOf "Domain Admins"               
            }

            if($domainUser.DelegateAccount -eq $True)
            {
                $rootDse = [ADSI]"LDAP://RootDSE"
                $principal = New-Object Security.Principal.NTAccount("DEV\$($domainUser.Name)")   
                DSACLS "$($rootDse.defaultNamingContext)" /G "$($principal):CA;Replicating Directory Changes"
                DSACLS "$($rootDse.configurationNamingContext)" /G "$($principal):CA;Replicating Directory Changes"
            }
        }
}
Param(
    [string] $DomainName = "dev.loc",
    [Parameter(Mandatory)]
    [Hashtable[]] $DomainUsers = $null
)