Just ran this for updating group in Viva via M365 underlying group. It's quick and dirty - feel free to adjust per your needs
Install Exchange Online module in case not installed
Install-Module -Name ExchangeOnlineManagement
Connect to Exchange Online
Connect-ExchangeOnline
Specify the group name and CSV file path
$GroupName = "viva_community_email_******@yourdomain.com"
$CSVFilePath = ".\File_To_Import.csv"
Note that the file should have a column with a heading of UserPrincipalName
This column should contain email addresses of everyone you want to import
Import the CSV file into a variable
$MembersToImport = Import-Csv $CSVFilePath
Get the group object
$Group = Get-UnifiedGroup $GroupName
$Members = Get-UnifiedGroupLinks -Identity $GroupName -LinkType Member
Write-Warning "Group Members: " ${Members}
Remove existing members if you want to replace with only what's in the CSV
Remove-UnifiedGroupLinks -Identity $Group -LinkType Members -Links $Members
Add new members from the CSV file
foreach ($member in $MembersToImport) {
Add-UnifiedGroupLinks -Identity $Group -LinkType Member -Links $member.UserPrincipalName
Write-Warning $member.UserPrincipalName
}
Write-Host "Members updated successfully."