The below links are a great way to provide feedback for the Microsoft future roadmap, research & development, and cloud first releases. Please give feedback and help the community steer in the right direction. Cheers!
The below code will post to Newsfeed for any user account you specify. Activity appears the same as if the user manually posted. This could be helpful for populating Newsfeed from external activity, custom event receivers, workflow, and other developer sources. Enjoy!
Screenshot
Code
using Microsoft.Office.Server.Social;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint;
using System;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
// Config
string siteUrl = "http://mysite";
string login = "i:0#.w|domain\\user";
using (SPSite site = new SPSite(siteUrl))
{
// Context
SPUser user = site.RootWeb.SiteUsers[login];
SPUserToken token = user.UserToken;
SPServiceContext ctx = SPServiceContext.GetContext(site);
using (new SPServiceContextScope(ctx))
{
// Init
UserProfileManager upm = new UserProfileManager(ctx);
UserProfile prof = upm.GetUserProfile(user.LoginName);
SPSocialFeedManager mgr = new SPSocialFeedManager(prof, ctx, token);
SPSocialPostCreationData post = new SPSocialPostCreationData();
// Text
post.ContentText = "hello world, look at {0}!";
post.UpdateStatusText = true;
// Link
SPSocialDataItem [] link = new SPSocialDataItem [1];
link[0] = new SPSocialDataItem();
link[0].ItemType = SPSocialDataItemType.Link;
link[0].Text = "My Cool Link";
link[0].Uri = new Uri("http://www.google.com");
post.ContentItems = link;
// Save
SPSocialThread thread = mgr.CreatePost(null, post);
}
}
}
}
}
Contributor is often too generic to match business needs. Below are 4 custom security roles with more granular purpose. Running the below PowerShell will create the roles (if missing) for a given web URL.
Enjoy!
NoDelete = Contribute without delete
AddOnly = Contribute without delete or edit
EditOnly = Contribute without add or delete
NoEdit = Contribute without edit
# #############################################################################
# NAME: AddCustomRoles.ps1
#
# COMMENT: This script creates two Custom Access levels for
# a given SharePoint URL.
#
# * NoDelete = Contribute without delete
# * AddOnly = Contribute without delete or edit
# * EditOnly = Contribute without add or delete
# * NoEdit = Contribute without edit
#
# REQUIRE: Permission to unlock account
# USAGE: .\AddCustomRoles.ps1 http://sharepoint/sites/team
#
# #############################################################################
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,Position=1)]
[string]$url
)
Write-Host "Opening $url ... "
$web = Get-SPWeb $url
Write-Host "OK" -ForegroundColor Green
#### CREATE NODELETE
$nd = $web.RoleDefinitions |? {$_.Name -eq "NoDelete"}
if ($nd) {
Write-Host "Found NoDelete" -ForegroundColor Green
} else {
Write-Host "Missing NoDelete"
Write-Host "Adding NoDelete ..."
$noDeleteRole = New-Object "Microsoft.SharePoint.SPRoleDefinition"
$noDeleteRole.Name = "NoDelete"
$noDeleteRole.Description = "Can view, add, and update list items and documents."
$noDeleteRole.BasePermissions = "AddAndCustomizePages,AddDelPrivateWebParts,AddListItems,BrowseDirectories,BrowseUserInfo,CreateAlerts,EditListItems,EditMyUserInfo,ManagePersonalViews,Open,OpenItems,UpdatePersonalWebParts,UseClientIntegration,UseRemoteAPIs,ViewFormPages,ViewListItems,ViewPages,ViewVersions"
$web.RoleDefinitions.Add($noDeleteRole)
Write-Host "OK" -ForegroundColor Green
}
#### CREATE ADDONLY
$ao = $web.RoleDefinitions |? {$_.Name -eq "AddOnly"}
if ($ao) {
Write-Host "Found AddOnly" -ForegroundColor Green
} else {
Write-Host "Missing AddOnly"
Write-Host "Adding AddOnly ..."
$addOnlyRole = New-Object "Microsoft.SharePoint.SPRoleDefinition"
$addOnlyRole.Name = "AddOnly"
$addOnlyRole.Description = "Can view and add items and documents."
$addOnlyRole.BasePermissions = "AddAndCustomizePages,AddDelPrivateWebParts,AddListItems,BrowseDirectories,BrowseUserInfo,CreateAlerts,EditMyUserInfo,ManagePersonalViews,Open,OpenItems,UpdatePersonalWebParts,UseClientIntegration,UseRemoteAPIs,ViewFormPages,ViewListItems,ViewPages,ViewVersions"
$web.RoleDefinitions.Add($addOnlyRole)
Write-Host "OK" -ForegroundColor Green
}
#### CREATE EDITONLY
$eo = $web.RoleDefinitions |? {$_.Name -eq "EditOnly"}
if ($eo) {
Write-Host "Found EditOnly" -ForegroundColor Green
} else {
Write-Host "Missing EditOnly"
Write-Host "Adding EditOnly ..."
$EditOnlyRole = New-Object "Microsoft.SharePoint.SPRoleDefinition"
$EditOnlyRole.Name = "EditOnly"
$EditOnlyRole.Description = "Can view, and update list items and documents."
$EditOnlyRole.BasePermissions = "AddAndCustomizePages,AddDelPrivateWebParts,BrowseDirectories,BrowseUserInfo,CreateAlerts,EditMyUserInfo,ManagePersonalViews,Open,OpenItems,UpdatePersonalWebParts,UseClientIntegration,UseRemoteAPIs,ViewFormPages,ViewListItems,ViewPages,ViewVersions"
$web.RoleDefinitions.Add($EditOnlyRole)
Write-Host "OK" -ForegroundColor Green
}
#### CREATE NOEDIT
$ne = $web.RoleDefinitions |? {$_.Name -eq "NoEdit"}
if ($ne) {
Write-Host "Found NoEdit" -ForegroundColor Green
} else {
Write-Host "Missing NoEdit"
Write-Host "Adding NoEdit ..."
$NoEditRole = New-Object "Microsoft.SharePoint.SPRoleDefinition"
$NoEditRole.Name = "NoEdit"
$NoEditRole.Description = "Can add, view and delete list items and documents."
$NoEditRole.BasePermissions = "AddAndCustomizePages,AddDelPrivateWebParts,AddListItems,BrowseDirectories,BrowseUserInfo,CreateAlerts,DeleteListItems,DeleteVersions,EditMyUserInfo,ManagePersonalViews,Open,OpenItems,UpdatePersonalWebParts,UseClientIntegration,UseRemoteAPIs,ViewFormPages,ViewListItems,ViewPages,ViewVersions"
$web.RoleDefinitions.Add($NoEditRole)
Write-Host "OK" -ForegroundColor Green
}
SharePoint names the blog created in a personal site “Blog.” At scale this is confusing because everyone’s blog has exactly the same title (“Blog”).
The below PowerShell will rename to “{FirstName LastName} – Blog” for a more user friendly experience across search results, follow site recommendations, and site directory.
Cheers!
#get all personal site blogs
$webs = Get-SPSite -Limit All |? {$_.RootWeb.WebTemplate -eq "SPSPERS"} | Get-SPWeb -Filter {$_.Template -eq "BLOG"} -Limit All
foreach ($w in $webs) {
#progress display
$w.Url
#filter
if ($w.Title -eq "Blog") {
#AD lookup
$splits = $w.Site.Url.Split("/")
$login = $splits[$splits.length - 1]
$user = Get-ADUser $login
$name = $user.Name
$title = "Blog - $name"
#save
$w.title = $title
$w.Update()
$w.Title
}
}