Office 365

Retrieving Office 365 message center using PowerShell

Posted on

How to Retrieving Office 365 message center Information using PowerShell

Quick handy script to do that, and add the output to a SharePoint list, you can exclude the list part if you want
Prerequisite is to create the SharePoint list

Import-Module O365ServiceCommunications
# Add references to SharePoint client assemblies and authenticate to Office 365 site - required for CSOM
Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.Runtime.dll"
# Specify tenant admin and site URL
$SiteUrl = ""
$ListName = "MessageCenter"
$UserName = ""
$SecurePassword = ConvertTo-SecureString "Pa$$word" -AsPlainText -Force
# Bind to site collection
$ClientContext = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
$ClientContext.Credentials = $credentials
# Get List
$List = $ClientContext.Web.Lists.GetByTitle($ListName)
Add-PSSnapin Microsoft.SharePoint.Powershell
$webUrl = ""
$listName = "Message Center"
$web = Get-SPOWeb $webUrl
$list = $web.Lists[$listName]
$User = ""
$Pass = "Pa$$word"
$cred = New-Object System.Management.Automation.PSCredential($User,(ConvertTo-SecureString $Pass -AsPlainText -Force));
#$cred = Get-Credential -Message "Office 365 Credentials" -UserName $username
# gather events from the Service Communications API
$MySession = New-SCSession -Credential $cred
$Events = Get-SCEvent -EventTypes Message -PastDays 100 -SCSession $MySession |
Select-Object Id, Title, StartTime, Service, EventType, Status, @{n='Message';e={$_.messages[0].messagetext}}
if ($Events)
$Tables = foreach ($Event in $Events)
$ListItemCreationInformation = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
$newItem = $list.addItem($ListItemCreationInformation)
$newItem["Title"] = $Event.Id.ToString()
$newItem["MessageTitle"] = $Event.Title.ToString()
$newItem["Date"] = $Event.StartTime.ToString()
$newItem["Message"] = $Event.Message.ToString()
$newItem["Service"] = $Event.Service.ToString()
$newItem["EventType"] = $Event.EventType.ToString()
$newItem["Status"] = $Event.Status.ToString()
write-host "Item created: "
Write-Host "Completed"

PowerShell for Show documents in Delve and in the Discover view in OneDrive for Business

Posted on Updated on

Delve is relatively still young baby for Microsoft.

Recently we have a requirement to enable the option of Show documents in Delve and in the Discover view in OneDrive for Business.

This can be done easily via a GUI like below

Go to App lancher and pick Delve –> Select Feature settings –> then enable Show documents in Delve and in the Discover view in OneDrive for Business


to do this via script, please copy and paste this in your PowerShell ISE and run it.


  1. Windows Internet Explorer
  2. You have to login at least 1 time through because the script will use your existing credentials

#Deactivate Delve Simulator
$ie = New-Object -COMObject InternetExplorer.Application
$jsonlink = ""
#You can replace your the variable below with a static name, but her it logs with your current windows credentials
$searcher = [adsisearcher]"(samaccountname=$env:USERNAME)"
$mail = $searcher.FindOne().Properties.mail
$userName =$mail.replace("@","_").replace(".","_")
#Navigate to your download file/location
Write-host "Processing Request for: " $user.UPN
$ie.visible = $true
while($ie.Busy){Sleep 4}
while($ie.Document.location.href -like '**'){
$ie.document.IHTMLDocument3_getElementsByTagName("table") | Where-Object{$_.Id -eq $userName} | select -First 1).click()
Sleep 4
Write-Host "Ensure you are in the Delve Screem ..." -ForegroundColor Yellow
#[void](Read-Host 'Press Enter to continue after login ' -ErrorAction SilentlyContinue)
#Navigate to Properties
Sleep 4
#Open Settings
($ie.document.IHTMLDocument3_getElementsByTagName("a") | Where-Object{$_.className -eq "o365cs-settings-deeplink wf-size-x12 ms-fcl-ns o365button"} | select -First 1).click()
Sleep 4
##Switch Value
$checkBox =$ie.document.IHTMLDocument3_getElementById("enableDocumentsCheckbox")
$oldValue = $checkBox.value
if($oldValue -eq "on" -or $oldValue -eq "off")
$checked = $
Sleep 2
#$newValue = $ie.document.IHTMLDocument3_getElementById("enableDocumentsCheckbox").value
Sleep 1
($ie.document.IHTMLDocument3_getElementsByTagName("button") | Where-Object{$_.className -eq "SharingActivityPanel-module_button_delve"} | select -First 1).click()
Sleep 4
$ie.document.location = $ie.document.location
write-host "Done Successfully Delve Flag Switched"
catch [System.Exception]{
write-host "Failed, Try Again" $_.Exception
finally {
while($ie.Busy){Sleep 1}