0

I want to combine these below command to add all Security Groups to multiple computer or user objects. As like

Get-ADPrincipalGroupMembership
Add-ADPrincipalGroupMembership

So that what the Get-ADPrincipalGroupMembership will return from a computer or user object those will add to multiple computers or users object using Add-ADPrincipalGroupMembership. This pull a list of security groups as a Member Of any computer. I want to add those security groups to other few computers as Member Of.

$Host_name = Read-Host "Please enter the host name "
$Host_name = $Host_name.ToUpper()
Write-Host The computer $Host_name has Member Of below security groups. -ForegroundColor White -BackgroundColor DarkBlue
$allgroups = Get-ADComputer -Identity $Host_name -Properties *  | Get-ADPrincipalGroupMembership | Select-Object name | Format-Table -HideTableHeaders #| Out-String | ForEach-Object { $_.Trim("`r","`n") } 
$allgroups
$New_Hosts = Read-Host "Enter the new host name to be the Member Of same groups "
Get-ADComputer -Identity $New_Hosts 
foreach ($nh in $allgroups) 
    { 
    #Add-ADPrincipalGroupMembership -Identity $New_Hosts -MemberOf $nh
    #Add-ADPrincipalGroupMembership -MemberOf $nh
    #Get-ADComputer -Identity $New_Hosts | Add-ADPrincipalGroupMembership -MemberOf $nh
    }

Manas Dash
  • 53
  • 8

0 Answers0