365-PSScripts/Replace-GroupMembers.ps1

13 lines
513 B
PowerShell
Raw Normal View History

2023-12-18 18:18:44 +00:00
Connect-ExchangeOnline
$newnames = Import-Csv "" #Path to CSV with 1 column called 'Name' with the list of UserPrincipleNames to be added to the group
$group = "" #Name of the Group
$oldnames = Get-UnifiedGroupLinks -Identity $group -LinkType Members
ForEach ($oldname in $oldnames){Remove-UnifiedGroupLinks -Identity $group -LinkType Members -Links $oldname.name -Confirm $true}
ForEach ($newname in $newnames){Add-UnifiedGroupLinks -Identity $group -LinkType Members -Links $newname.Name}