When using Active Directory groups, with computers in, to deploy applications in SCCM it can sometimes be useful to copy group membership from one computer to another. This can be useful if a user change computer but is going to continue having the same applications.
The script below will copy the group membership from one computer to another.
To use the script do this:
- Copy the script below to a file and save the file to CopyComputerMembership.ps1
- Run the script on a computer with the PowerShell module ActiveDirectory installed and make sure that you have access to move the group membership.
- Run the script like this: CopyComputerMembership.ps1 -FromComputer <computername> -ToComputer <computername>
$ToClient = Get-AdComputer -Identity $ToComputer
$FromClient = Get-ADComputer -Identity $FromComputer -Properties MemberOf
Foreach ($Group in $Client.MemberOf)
$GroupObj = Get-ADGroup -Identity $Group
Add-ADGroupMember -Identity $GroupObj -Members $ToClient