I'm trying to bulk add multiple users into multiple different sites using this below script:
Connect-SpoService -Url https://xxxxxxxxxxxx-admin.sharepoint.com/
#Parameters
$URL=https://xxxxxx.sharepoint.com
$Site = Get-SpoSite -Limit ALL| Where-Object {$_.Url -like '*family*'} | Select-Object -ExpandProperty Url
$Group = (Get-SPOSiteGroup -Site $site | Where-Object {$_.Title -like '*member*'}).title
$Login = 'xxxxxxx@xxxxxxx.com'
ForEach ($Site in $Sites) {
Try {
Add-SPOUser -Site $Site -LoginName $login -Group $group.Title
write-host "adding $login to $site"
}
Catch {
write-host -f Red "Error Adding User to the Site: $($Site.URL)" $_.Exception.Message -foregroundcolor Red
}
}
My other option was to export a CSV of sites then reiterate through each row to add the users this way. My only roadblock is finding the best way to add them to the corresponding group; it doesn't seem like I can achieve this without using the full group name.
What am I missing here?
Instead, whatever I ran up top returned nothing. Maybe it was because I didn't specify the group name in full.