Using Flow to publish SharePoint News and Post to Microsoft Teams

Sending notifications to users in Microsoft Teams when a SharePoint news item is posted is something which is commonly requested, both with clients and on the various tech forums which I frequent. It definitely makes sense, and there is a lot you can do, using Microsoft Flow, to send notifications in a number of different ways to suit your users regardless of generation and technological awareness.

In this blog post, we’ll look at how we can connect Flow to the site pages library, and how we can determine the page type, publishing status, and some basic content so we can ensure that our users are getting the right information at the right time.

With modern SharePoint sites, you get a great way of creating and editing news items. It’s so simple to be able to create the news item within the browser, hit publish, but then wonder why users aren’t flocking to come and read your content. Let’s face it, in the modern world of intranets we don’t spend our lives watching the home page waiting for the next piece of news to appear. We spend our time where we do our work, and the only time we’ll go elsewhere is if we know there’s something there for me to look at. Even with the roll-up of news posts to the SharePoint Portal page, I still need a poke every now and then to go and check it.

SharePoint still has the ability to generate alerts, when something is created or changed, immediately or on a daily basis. We’ve seen it and have been using it for as long as I can remember, and unfortunately, it’s never changed or improved over that time and doesn’t give us the flexibility to be able to customise the notifications which are being sent to our users. It still has its uses, but, in my opinion, not in this scenario.

SharePoint News

But before I dive into Flow and start creating my own notification Flow, there are a few things which I need to understand about pages created in the site pages and how they’re classified. All SharePoint news posts and pages are created within the same library, but through the SharePoint User Interface, I don’t really get to see how SharePoint can distinguish between them. Yet, it knows which items to pick and display using the SharePoint News web parts, and knows which ones to roll up. It does this by automatically setting a hidden metadata field called “Promoted state”. The promoted state can take one of three values:

  • 0 = Site Page
  • 1 = News Post in Draft
  • 2 = News Post Published

SharePoint will automatically take care of the setting of this field for me, so all I need to do is remember this field when I move across into Flow to create my notification Flow.

Microsoft Flow

For my trigger, I’m going to use the “When a file is created or modified (properties only)” trigger, the page will go through draft before being published. Even if I publish the news post immediately, it will initially change to promoted state 1, and then to promoted state 2. So I’m really only interested in the modified event. I’m also only really interested in the properties as everything I need for my notification can be found here.

When configuring your trigger, select the site where you want this Flow to run from. Then select the drop down for the library name. Notice that Site Pages doesn’t appear, only your modern document libraries. Whilst you can’t select it, you can manually type “Site Pages” into the library name, just ensure that you either select “Enter custom value” to start with or alternatively type in Site Pages and then select “Use Site Pages as custom value”.

Checking if the Item has been Published

Each time the page is saved, it is going to trigger my Flow, so I now need to check whether the news item is in a published state or not. This is where, I’m going to use the Promoted State metadata field to check whether I’m going to start notifying my users that I’ve posted something, or whether I’m going to stop processing any further,

To do this, I’m going to use a Condition control and build a condition on Promoted State. The only state I’m interested in is 2 (News Post published). If it’s 2, then I’m going to start sending my notifications, otherwise, I’m not going to do anything.

Checking if the Item has been Published

Each time the page is saved, it is going to trigger my Flow, so I now need to check whether the news item is in a published state or not. This is where, I’m going to use the Promoted State metadata field to check whether I’m going to start notifying my users that I’ve posted something, or whether I’m going to stop processing any further,

To do this, I’m going to use Condition control and build a condition on Promoted State. The only state I’m interested in is 2 (News Post published). If it’s 2, then I’m going to start sending my notifications, otherwise, I’m not going to do anything.

So with all of this information, whenever a new post is created in SharePoint News, it will Post to Teams in the Channel that I set it up. Below is my configuration screenshot.

Recover Deleted O365 Mailbox data into Shared Mailbox

  1. Connect to Exchange Online
  2. Get-Mailbox -SoftDeletedMailbox | fl name,exchangeguid​
    2. (Get-Mailbox -SoftDeletedMailbox ivan.eltarabishy@alamarfoods.com).ExchangeGuid


3. Create a Shared Mailbox – ivaneltarabishy@alamarfoods.com and get the ExchangeGuid for the shared mailbox
(get-mailbox ivaneltarabishy@alamarfoods.com).ExchangeGuid


4. Now, we will copy the data from the original deleted mailbox to the shared mailbox 

​5. Get-MailboxRestoreRequest for the status of the mailbox copy. 

Switch from Semi-Annual Channel to the Monthly Channel in O365


Consider a scenario where Office 365 ProPlus is installed on a machine from the Semi-Annual Channel.  Now let’s say, a new feature is introduced on the Monthly Channel which you would like to get.  Since you are on the Semi-Annual Channel you will have to wait for a few months before this feature is made available to the Semi-Annual Channel.  But what if you do not want to wait that long?  The answer is, switch to the Monthly Channel.

Some users have the semi-annual channel and others the monthly channel, The Monthly channel users get the latest updates. this could be due to the Office License that is assigned to the user. 
What I observed is that Business Premium users tend to have the “Monthly Channel” whereas the E3 users have the “Semi-Annual Channel” 
These cmd allow the E3 users to be assigned the Monthly channel in E3, that way the updates are synced across, and changes can be seen by new users

Below are the steps to switch channels:

  1. Identify the channel which you would like to switch to. Features and updates by channel are documented here.
  2. Launch Command Prompt as an administrator.
  3. Navigate to “C:\Program Files\Common Files\Microsoft Shared\ClickToRun\”
  4. Run the following command to change the desired channel, let’s say Monthly Channel Targeted “OfficeC2RClient.exe /changesetting Channel=Monthly” 

Note – You can use this command to switch to any channel using the corresponding Channel keyword listed below:

ChannelKeyword in CMD or ODT
  Monthly Channel (Targeted)  Channel=”Insiders“ or Channel=”FirstReleaseCurrent
  Monthly Channel  Channel=”Monthly” or Channel=”Current
  Semi-annual Channel (Targeted)  Channel=”Targeted” or Channel=”FirstReleaseDeferred
  Semi-annual Channel  Channel=”Broad” or Channel=”Deferred

To start the switch Channel process, run “OfficeC2RClient.exe /update user” from the cmd prompt path “C:\Program Files\Common Files\Microsoft Shared\ClickToRun\” 

This should be followed by a series of windows which will take you through the process of downloading and installing updates for the new channel that you have switched to.

PowerShell Commands for a O365 System Admin

Create New O365 User

Connect-MsolService​

New-Msoluser -UserPrincipalName torky.elenazy@alamarfoods.com -DisplayName "Torky ElEnazy" -FirstName Torky -LastName Elenazy -Country SA -MobilePhone +966594399666 -Fax SADP01334 -Department "Human Resources" -Title "Recruiter Assistant" -UsageLocation SA

Adding License to user

Set-MsolUserLicense -AddLicenses AlamarFoods:O365_BUSINESS_PREMIUM -UserPrincipalName mohammed.hemdan@alamarfoods.com

Add Manager Credentials – first connect to Exchange Online

Add Manager – MFA Enabled

Connect to EAC<Hybrid<Exchange Online Powershell with MFA

Connect-EXOPSSession -UserPrincipalName shrenik.salguna@alamarfoods.com

(in Hybrid PowerShell )

Set-User -Identity mohammed.hemdan@alamarfoods.com -Manager mohammed.roustom@alamarfoods.com

Set-ExecutionPolicy RemoteSigned

$UserCredential = Get-Credential

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

Import-PSSession $Session

Add to Distribution List – (Office365 Groups)

Add-DistributionGroupMember -Identity "Alamar Foods" -Member "kiran.venugopal@alamarfoods.com"

Add-DistributionGroupMember -Identity "Alamar Corporate" -Member "kiran.venugopal@alamarfoods.com"

Add to O365 Group

Add-UnifiedGroupLinks -Identity "Alamar Foods KSA" -LinkType Members -Links kiran.venugopal@alamarfoods.com

Create New User in Active Directory

New-ADUser -Name "Kiran Venugopal" -GivenName "Kiran" -Surname "Venugopal" -SamAccountName "kiran.venugopal" -UserPrincipalName "kiran.venugopal@alamarfoods.com" -Office "Head Office" -EmailAddress "kiran.venugopal@alamarfoods.com" -Mobile "+971551477891" -Title "KSA Financial Analyst" -Department "Finance" -Path "OU=Finance,OU=HO Users,OU=Saudi Arabia-HO,DC=alamarfoods,DC=local" -AccountPassword(Read-Host -AsSecureString "Aa123456") -Company "Alamar Foods | KSA" -City "Riyadh" -Country ‘SA’ -StreetAddress "AlOlaya District, Street No. 36, Building No. 3" -POBox ‘4748’ -Manager "usama.ruby" -Enabled $true

For MENAP Users

New-ADUser -Name "Mohamed Younes" -GivenName "Mohamed" -Surname "Younes" -SamAccountName "mohamed.younes" -UserPrincipalName "mohamed.younes@alamarfoods.com" -Office "Head Office" -EmailAddress "mohamed.younes@alamarfoods.com" -Mobile "+20106644628" -Title "Warehouse Supervisor" -Department "Supply Chain" -Path "OU=Commissary,OU=EG Users,OU=Egypt,OU=MENAP,DC=alamarfoods,DC=local" -AccountPassword(Read-Host -AsSecureString "Aa123456") -Company "Alamar Foods | Egypt" -City "Cairo" -Country ‘EG’ -Manager "mohamed.amer" -Enabled $true

Adding Manager thru CSV command

Create CSV; UserPrincipalName; (see desktop)

Manager

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

Import-PSSession $Session

Add Manager

Set-User -Identity mohammed.hemdan@alamarfoods.com -Manager mohammed.roustom@alamarfoods.com

Import-Csv "C:\Users\shrenik.salguna\Desktop\UpdateManager.csv" | foreach {Set-User -Identity $_.UserPrincipalName -Manager $_.Manager}

Get all properties of user

Get-User | gm

Get properties of user and manager

Get-User | select -Property Name,Manager

Export to CSV

Get-User | select -Property Name,Manager | Export-csv "C:\Users\shrenik.salguna\Desktop\Manager.csv"

"C:\Users\shrenik.salguna\Desktop\UpdateManager.csv" | foreach {Set-User -Identity $_.UserPrincipalName -Manager $_.Manager}