3

I am using the Community Site Feature. Users need to click the "Join Community" button to become a member.

I would like to have this "member list" be either manually pre-filled or even better use a "normal" SharePoint group to be mapped against this "member list".

Any idea how to do this?

1

If the problem is still occurs, try this PowerShell script:

 Add-PSSnapin "Microsoft.SharePoint.PowerShell"
 $site = Get-SPWeb -Identity http://<Your site address> 
 $listname = "Members" 
 $list = $site.Lists[$listname] 
 $users = Get-SPUser -Web $site -Group "<The name of the required group on $site>" -Limit all
 foreach ($user in $users){
     $newItem = $list.Items.Add()
     $newItem["Member"] = $user.ID
     $newItem.Update()
 }
 $list.Update()

This script goes through the group and adds each person in the community site.

After the completion all you need to do is ask someone to join the community to recount properly the counter in the "What's happening" web-part.

1

Based on Tim's version above, this version is CSOM. Our farm is set up to use our corporate ID numbers. This takes a text file with a list of those numbers and adds them to the community.

# This script requires at least PowerShell 3.0 to work
# Please install the SharePoint client components SDK - http://www.microsoft.com/en-us/download/details.aspx?id=35585 prior to running this script.
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.UserProfiles.dll"

# A SharePoint Community site url -- have not tested with a regular site with community features
$spSiteURL = "https://<url to site>"
$spListTitle = "Community Members"

$ListItemInfo = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($spSiteURL)

# Get site context
$spWeb = $ctx.Web
$ctx.Load($spWeb)
$ctx.ExecuteQuery()

# Load the up list
$spList = $spWeb.Lists.GetByTitle($spListTitle)
$ctx.Load($spList)
$ctx.ExecuteQuery()

# Load up fields
$spFields = $spList.Fields
$ctx.Load($spFields)
$ctx.ExecuteQuery() 

# A simple text file with one ID per line. 
$nuids = Get-Content "C:\<file.txt>"

# loop through each ID in the file and create a new user in the Community Members list
foreach($item in $nuids)
{
    try {
        $user = $spweb.EnsureUser($item)
        $ctx.Load($user)
        $ctx.ExecuteQuery() 

        # Get a new item object
        $nItem = $spList.AddItem($ListItemInfo)

        $nitem["Member"] = $user.Id
        $nitem.Update()
        $ctx.ExecuteQuery()
    }
    catch [system.exception]{
        # duplicate IDs or unknown IDs will create errors
        # but the script will keep running.
        write-host $item $_.Exception.Message
    }
}

# Users are added to the community, but no notice will appear in their feed
# the number of members in the "Whats happening" webpart does not update,
# After running the script, have one person join through the UI to set the number of members 

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.