I am trying to set up a script to copy the 'Members Of' from specific accounts to a new user account after creating the user.
Something very similar to this: https://www.adaxes.com/tutorials_AutomatingDailyTasks_AutomaticallyChangeGroupMembershipUsingScripts.htm
But listing each group one by one (there are around 20 per department), would not work for us.
I'm looking to do this per department, which I already have business rules for. And then, a script to simply copy all of the members of groups, from 'Template_Account" to "New user".
I tried to use something like this, but with no luck:
$CopyFromThisUser = "HTB-Template"
$CopymembersToThisUser = "%sAMAccountName%"
Get-ADUser -Identity $CopyFromThisUser -Properties memberof | Select-Object -ExpandProperty memberof | Add-ADGroupMember -Members $CopymembersToThisUser
The ones I have found on here, do not meet our requirements and we would rather do this using accounts used as templates rather than having one large powershell to say which groups to add to. So that the service desk can easily make changes to the accounts as required due to the ever changing nature of the business.
Is someone able to help me with this?