powershell 一次添加多个组的Add-ADGroupMember问题

jtoj6r0c  于 2023-05-17  发布在  Shell
关注(0)|答案(1)|浏览(160)

我目前的问题是,当我想将组添加到组时,它会给我一个ParameterBindingException。这是我目前所拥有的:

$MissingGroup = 'GGroup01'

$getADGroupSplat = @{
    # find all groups where `$MissingGroup` is NOT a member of
    LDAPFilter = '(!memberof={0})' -f (Get-ADGroup $MissingGroup).DistinguishedName
    SearchBase = 'OU=xxxxxxxxxxx,DC=xxxxxxxxxxxxx,DC=xx'
}

$Group = Get-ADGroup @getADGroupSplat

$actualGroup = $Group | Where-Object {$_.Name -like "GGroup_A0*_Security"} | Format-List Name

Add-ADGroupMember -Identity $MissingGroup -Members $actualGroup

有人能帮帮我吗
错误是:

Add-ADGroupMember : Der Parameter "Members" kann nicht gebunden werden. Objekt vom Typ "Microsoft.ActiveDirectory.Management.ADPrincipal. Der Adapter kann den Wert 
der Name-Eigenschaft nicht festlegen." kann nicht erstellt werden.
In Zeile:1 Zeichen:61
+ ... -ADGroup -Identit $CitrixGG | Add-ADGroupMember -Members $actualGroup
+                                                              ~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Add-ADGroupMember], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.ActiveDirectory.Management.Commands.AddADGroupMember

错误是德语。

hc8w905p

hc8w905p1#

问题是Format-List。是用来把数据写到屏幕上的。
下面是更新后的代码:

$MissingGroup = 'GGroup01'
$getADGroupSplat = @{
    # find all groups where `$MissingGroup` is NOT a member of
    LDAPFilter = '(!memberof={0})' -f (Get-ADGroup $MissingGroup).DistinguishedName
    SearchBase = 'OU=xxxxxxxxxxx,DC=xxxxxxxxxxxxx,DC=xx'
}
$Group = Get-ADGroup @getADGroupSplat
$actualGroup = $Group | Where-Object {$_.Name -like "GGroup_A0*_Security"} | Select-Object -ExpandProperty Name
Add-ADGroupMember -Identity $MissingGroup -Members $actualGroup -MemberIdentity (Get-ADGroupMember $actualGroup).SamAccountName

相关问题