A personal blog can be a great tool for you to contribute your thoughts and ideas. Office 365 provides the capability for everyone to have a personal blog that can be accessed via your profile page.
When you create a new blog post this will be automatically be view-able by all employees. If you do not want to have this capability or manage this in any way it can be done via PowerShell. The example I put together will remove viewers access from all existing blogs so they can only be seen by the owner.
To get started we need a high level understanding of what these blogs are and how they work. I won’t go into all of the details of this because Benjamin Niaulin has already put it together in this great post:
The highlights to support this post are:
- When a user follows the links to create a new blog post a new site collection is built with the managed path of /portals/personal with a site name of your user account
- i.e. tenant.sharepoint.com/portals/personal/dmadelung
- These are not viewable in any SP Admin center and Get-SPOSite will not work
- Site collections are only built after a user initiates the creation so not all users will have one
- Blog posts (stories) are creates at pages in the pages library on your site collection
- Permissions are handled with SharePoint permissions and inherited down with a Contributors, Creators, and Viewers SharePoint Group
- The viewers group includes “Everyone except external users” by default
- The blogs are NOT deleted when a user leaves like their OneDrive site collection
And here are details the details from Microsoft around personal blog posts in Office 365:
Removing existing permissions via PowerShell
As this is all hosted in SharePoint there could be multiple ways that we can control these. Unfortunately I couldn’t find a way to control things as scale but there is a small UserVoice submission for it. What I wanted to ensure was that creators could still get to their content but no one else could view anything. The path I took to manage these was through PowerShell and CSOM (Client Side Object Model)
Here is link to the GitHub repo and I will break it down below along with the script.
Here are some key things to note:
- I can not confirm that doing this is the best practice but it was the easiest way I found to control these without a any administrator controls available to us.
- This is currently built to run on demand but could be updated to run on a schedule via something like Azure Automation.
- To catch everything it will need to run on a schedule because any future sites will not be caught.
- This could be updated to be used as a reporting tool or identification tool for cleanup.
- I would comment out the actual removal of the permissions and put some logging in to test before fully running.
- Also if you have any changes please update the repo!
- This queries the user profile service in SharePoint Online to get the full list of users which could be huge.
- I didn’t test this on a very large environment so this could take awhile to run or need to be enhanced for scale.
- All of the user profile gathering was copied from this post from Microsoft on how to display a list of OneDrive for Business site collections
To get started with CSOM & PowerShell with SharePoint Online here is a good blog post from Chris O’Brien. You can get the latest version of SharePoint Online CSOM here. If you download the nuget file you can change the file extension to .zip and extract the .dlls.
To utilize the script make sure you fill out the appropriate variables and more information about what this will do is below the script. Make sure you test any script you get online before you really run it!
# Use this script to remove viewer permissions from all user delve blogs that have been created # A user will still be able to view their existing blogs and create blogs but people will not be able to see them # This would allow you to choose in the future if you want to make them live # # This could be updated to run on a schedule as this will not remove any new blogs that are created ### ENTER YOU VARIABLES HERE ### #Path to the SP CSOM files $csomPath = "C:\...." ################ #Prompt for parameters #TenantDomain is beginning of "tenantdomain.sharepoint.com.." $TenantDomain = Read-Host -Prompt "Tenant domain" $AdminAccount = Read-Host -Prompt "Admin account" $AdminPass = Read-Host -Prompt "Password for $AdminAccount" –AsSecureString #Set SharePoint admin url $AdminURI = "https://" + $TenantDomain + "-admin.sharepoint.com" #Get CSOM files Add-type -Path "$csomPath\Microsoft.SharePoint.Client.dll" Add-type -Path "$csomPath\Microsoft.SharePoint.Client.Runtime.dll" #Begin the process $loadInfo1 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client") $loadInfo2 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime") $loadInfo3 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.UserProfiles") #Set credentials for CSOM $creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($AdminAccount, $AdminPass) #Add the path of the User Profile Service to the SPO admin URL, then create a new webservice proxy to access it $proxyaddr = "$AdminURI/_vti_bin/UserProfileService.asmx?wsdl" $UserProfileService= New-WebServiceProxy -Uri $proxyaddr -UseDefaultCredential False $UserProfileService.Credentials = $creds #Set variables for authentication cookies $strAuthCookie = $creds.GetAuthenticationCookie($AdminURI) $uri = New-Object System.Uri($AdminURI) $container = New-Object System.Net.CookieContainer $container.SetCookies($uri, $strAuthCookie) $UserProfileService.CookieContainer = $container #Sets the first User profile, at index -1 $UserProfileResult = $UserProfileService.GetUserProfileByIndex(-1) Write-Host "Starting- This could take a while." #Getting total number of profiles $NumProfiles = $UserProfileService.GetUserProfileCount() $i = 1 #Create array to track users $users = @() #As long as the next User profile is NOT the one we started with (at -1)... While ($UserProfileResult.NextValue -ne -1) { Write-Host "Reviewing profile $i of $NumProfiles" #Look for the Point Publishing Blog url object in the User Profile and retrieve it #It will be empty for users which it has not been created for #Get personal blog publishing URL $Prop = $UserProfileResult.UserProfile | Where-Object { $_.Name -eq "SPS-PointPublishingUrl" } $Url= $Prop.Values[0].Value #Get user UPN - Can be used for reporting #$Prop = $userProfileResult.UserProfile | Where-Object { $_.Name -eq "SPS-UserPrincipalName"} #$Upn= $Prop.Values[0].Value #If the blog site exists then add it to an array to review if ($Url) { $users += $Url } #And now we check the next profile the same way... $UserProfileResult = $UserProfileService.GetUserProfileByIndex($UserProfileResult.NextValue) $i++ } #Loop through all identified sites to remove blog viewers foreach($user in $users){ #Set blog site url $siteurl = "https://" + $TenantDomain + ".sharepoint.com" + $user #Connect to blog site collection $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteurl) $ctx.Credentials = $Creds #Connect to web and get site groups $web = $ctx.Web $groups = $ctx.Web.SiteGroups $ctx.Load($web) $ctx.Load($groups) $ctx.ExecuteQuery() #Get the viewers group $group = $groups | where { $_.Title -eq "Viewers"} if($group){ #Get the users in the viewers group $users = $group.Users $ctx.Load($users) $ctx.ExecuteQuery() #Remove all users from the viewers group foreach($u in $users){ $group.Users.RemoveByLoginName($u.LoginName) $web.Update() $ctx.ExecuteQuery() } } }
The end result will be that all existing blog sites will have anyone in the Viewers SharePoint Group removed
Before…
After..