2

Is it possible to add an AD group into SharePoint. I've created a user group in the Office 365 portal, which appears to be stored in AD. Is there a way of searching for this AD group and adding it.

SharePoint allows you to do this through the UI but I cant see it anywhere in the API. If not is there away of importing all of the groups?

0

Using EnsureUser works http://msdn.microsoft.com/en-us/library/office/dn499819(v=office.15).aspx#bk_WebEnsureUser

Just pass the GroupName and you can get the principalId of the group

0

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 = "user@tenant.onmicrosoft.com",

    $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"
}
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.