It might not be te most elegant solution, but this will get them into which ever group you put as $group. If your AD is on-prem follow this first. If they are already synced to your Azure AD, then just run the below code.
function Connect-SPOSite() {
param (
$admuser = "[email protected]",
$admsite = "https://tenant-admin.sharepoint.com"
)
if ((Get-Module Microsoft.Online.SharePoint.PowerShell).Count -eq 0) {
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
}
$cred = Get-Credential $admuser
Connect-SPOService -Url $admsite -Credential $cred
}
$site = "https://tenant.sharepoint.com"
$users = Get-Content Path to users.txt
$group = the group you want them in
foreach ($user in $users)
{
try
{
Add-SPOUser -Site $site -LoginName $user -Group $group
Write-Output "Successfully added user $user, $_ to group"
}
catch
{
Write-Output "Error adding user $user, $_ to group"
}
}