PowerShell DSC组资源-“找不到具有提供的名称的主体”


8

我正在尝试使用PowerShell DSC将域组添加到本地管理员组。这是代码:

Configuration TestSetup {
    Node localhost {
        Group Administrators {
            GroupName = "Administrators"
            MembersToInclude = "MYDOMAIN\TheAdministratorsGroup"
        }
    }
}

运行它会导致以下错误:

PowerShell provider MSFT_GroupResource  failed to execute Test-TargetResource functionality with error message: Could not find a principal with the provided name [mydomain\theadministratorsgroup]
    + CategoryInfo          : InvalidOperation: (:) [], CimException
    + FullyQualifiedErrorId : ProviderOperationExecutionFailure
    + PSComputerName        : localhost

主体确实存在,我可以通过GUI并使用手动添加主体net localgroup

我知道DSC配置会在该SYSTEM帐户下执行,所以我认为这可能是该SYSTEM帐户要查询Active Directory 的权限问题。但是,我已经SYSTEM使用PsExec 作为帐户运行了cmd,并且能够将域组添加到本地管理员组而没有任何麻烦。

Answers:


4

您必须指定凭据:

例:

获取凭证的方式:

$securedstring = ConvertTo-SecureString -String $Password -AsPlainText -Force
[PSCredential]$cred = New-Object System.Management.Automation.PSCredential ($UserName, $securedstring)

这是您配置DSC资源所需的代码

$ConfigurationData = @{
    AllNodes = @(
        @{
            NodeName="*"
            PSDscAllowPlainTextPassword=$true
         }
        @{
            NodeName="SRV2-WS2012R2"
         }
        @{
            NodeName="SRV3-WS2012R2"
         }
   )
}


Node $AllNodes.NodeName
{
    LocalConfigurationManager
    {
        RebootNodeIfNeeded = $false
    }

    Group $group.Name
    {
        GroupName = $group.Name
        Ensure = $group.Ensure
        Members = $group.Members
        Credential = $cred
    }
}

然后简单地执行

ProcessDscResources -ConfigurationData $ConfigurationData -OutputPath $folderPathTmp

Start-DscConfiguration -Wait -Force -Path $folderPathTmp

非常感谢@Jupaoi,这很有用,并且在官方文档中没有记录。
内森2014年

有一种方法可以告诉它,它应该只使用“当前凭据”
TGlatzer
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.