Hide Microsoft Flow “Flows” Button on SharePoint Libraries/Lists

Microsoft Flow is a very useful integration tool released by Microsoft in Office 365. But in most of the cases, it started rolling out to all Office 365 users and started to show the Flow button in all SharePoint Lists/Libraries where modern experiences where activated. In some cases, IT would like to hide this option, in order to prevent parallel apps or flows from being developed outside IT.

Capture

How can we do this?

There is no Out-of the box way to disable Microsoft Flow from SharePoint sites via a browser. But you can achieve this via PowerShell + CSOM.

First of all, you’ll need to have the latest version of SharePoint Client Components installed, so that PowerShell can use the latest SharePoint Online client object model DLL’s.

Here’s the full working PowerShell Script (or if you prefer, take a look at my post on Technet):

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client"| Out-Null 
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime"| Out-Null 
 
# Variables with prompts 
$siteUrl = Read-Host -Prompt “Enter Site URL” 
 
$username = Read-Host -Prompt “Enter username” 
$password = Read-Host -Prompt “Enter password” -AsSecureString 
 
$subwebcheck = Read-Host -Prompt "Do you want to process subsites? (enter 'Y' if yes)" 
 
# Generate ClientContext(ctx) function so we can reuse 
function GetClientContext($siteurl$username$password) { 
     $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteurl)  
     $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username$password)  
     $ctx.Credentials = $credentials 
     return $ctx 
} 
 
$ctx = GetClientContext $siteurl $username $password 
 
# Verify connection 
if ($ctx.ServerObjectIsNull.Value) {  
    Write-Host "Unable to connect to: '$siteUrl'" -ForegroundColor Red 
} else { 
    Write-Host "Connected to: '$($siteUrl)'" -ForegroundColor Green  
 
    $rootWeb = $ctx.Web 
    $ctx.Load($rootWeb) 
    $ctx.ExecuteQuery() 
 
    # Update root site 
    Write-Host $rootWeb.Url "is being updated to disable Microsoft Flow button" 
    $rootWeb.DisableFlows=$true 
    $rootWeb.Update() 
    $ctx.Load($rootWeb) 
    $ctx.ExecuteQuery() 
    Write-Host "DisableFlows is now" $rootWeb.DisableFlows "for the site:" $rootWeb.Url -ForegroundColor Green 
        
    if ($subwebcheck -eq "Y") { 
         
        # Work with all subsites 
        Write-Host "Processing subsites..." -ForegroundColor Yellow 
        $childWebs = $rootWeb.Webs 
        $ctx.Load($childWebs) 
        $ctx.ExecuteQuery() 
        foreach ($childWeb in $childWebs) 
        { 
            processsubsites $childWeb.url 
        } 
    } 
} 
 
 
    # Function to loop through subsites and setting values 
function processsubsites($siteurl){ 
        $ctx = GetClientContext $siteurl $username $password 
        $rootWeb = $ctx.Web 
        $childWebs = $rootWeb.Webs 
        $ctx.Load($rootWeb) 
        $ctx.Load($childWebs) 
        $ctx.ExecuteQuery() 
 
        # Perform update for all template types except APPs to disable Microsoft Flow Button 
        if($rootWeb.WebTemplate -ne "APP"){ 
            Write-Host $rootWeb.Url "is being updated to disable Microsoft Flow button" 
            $rootWeb.DisableFlows=$true 
            $rootWeb.Update() 
            $ctx.Load($rootWeb) 
            $ctx.ExecuteQuery() 
            Write-Host "DisableFlows is now" $rootWeb.DisableFlows "for the site:" $rootWeb.Url -ForegroundColor Green 
        } 
 
        # Loop subsites of subsites of subsites...etc 
        foreach ($childWeb in $childWebs) 
        {            
            processsubsites $childWeb.url 
        } 
}

You can download the PS1 file here:

Leave a Reply

Your email address will not be published. Required fields are marked *