Office 365 – Update User Profile Property using PowerShell and CSOM

Here is a quick tip on how you can automate the update of Office 365 user profile property using the PowerShell and Client Side Object Model (CSOM).

 

$filePath = "D:\SCRIPTS\OFFICE365"
Set-Location $filePath
Add-Type -Path (Resolve-Path "Microsoft.SharePoint.Client.dll")
Add-Type -Path (Resolve-Path "Microsoft.SharePoint.Client.Runtime.dll")
Add-Type -Path (Resolve-Path "Microsoft.SharePoint.Client.UserProfiles.dll")

Write-host "Client Library Module(s) Loaded...." -ForegroundColor Green
# Authenticate
$userName = "YOUR USERNAME" 
$siteUrl = "YOUR SITE COLLECTION URL"
$pwd = Read-Host -AsSecureString "Please enter your password"
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl) 
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName, $pwd)
$peopleManager = new-object Microsoft.SharePoint.Client.UserProfiles.PeopleManager($ctx);
$personProperties = $peopleManager.GetMyProperties();
$ctx.Load($personProperties);
$ctx.ExecuteQuery();
$peopleManager.SetSingleValueProfileProperty($personProperties.AccountName, "AboutMe", "I LOVE OFFICE 365 !!!");
$ctx.ExecuteQuery();

Quick Tip: Office 365 – Document Upload and metadata

One of my client recently reported an interesting point when uploading document to Office 365 document library in SharePoint Online. I wanted to share the experience and workaround we used for this.

Typically (on-prem) when you have a metadata in your document library, after uploading document, SharePoint will take you straight to metadata screen. Where you will have option to enter metadata and then document will be checked-in. Now for on-prem version it works like this even if your metadata are not mandatory. So for example you have two metadata in your document library and both are not mandatory  SharePoint will still give you an option to pick metadata before checking-in the document.

This is not the default behavior with Office 365. In SharePoint Online if your metadata are not mandatory SharePoint will check document in without prompting you to enter your metadata. From my experience I can tell that this behavior will not work for most of the business users. 🙂

The solution (or workaround if you will) was rather simple in this case. All you have to do is go to Document Library setting and turn on the “Allow Management of Content Types” to True. Do not make any other changes but just turn the content type management to ON and that will bring SharePoint to sense and it will then start showing you the Metadata page. 🙂

I am not 100% sure the reason behind this change in behavior and still in process of figure out why this change was implemented in Office 365.

If you are using your metadata as part of your Content Type (which I think should be the case for the most part) then you are golden.

Cheers.