加入收藏 | 设为首页 | 会员中心 | 我要投稿 辽源站长网 (https://www.0437zz.com/)- 云专线、云连接、智能数据、边缘计算、数据安全!
当前位置: 首页 > 服务器 > 搭建环境 > Windows > 正文

Windows – PowerShell DSC组资源 – “找不到具有提供名称的主

发布时间:2021-01-18 06:39:37 所属栏目:Windows 来源:网络整理
导读:我正在尝试使用Power Shell DSC将域组添加到本地管理员组.这是代码: Configuration TestSetup { Node localhost { Group Administrators { GroupName = "Administrators" MembersToInclude = "MYDOMAINTheAdministratorsGroup" } }} 运行时,这会导致以下错

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

Configuration TestSetup {
    Node localhost {
        Group Administrators {
            GroupName = "Administrators"
            MembersToInclude = "MYDOMAINTheAdministratorsGroup"
        }
    }
}

运行时,这会导致以下错误:

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

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

我知道DSC配置在SYSTEM帐户下执行,所以我认为这可能是SYSTEM帐户想要查询Active Directory的权限问题.但是我使用PsExec运行cmd作为SYSTEM帐户,我能够毫无困难地将域组添加到本地管理员组.

您必须指定凭据:

例:

获取凭据的方式:

$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

(编辑:辽源站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读