OneDrive for Business notifications with Powershell
Mobile Push Notifications
Mobile Push Notifications allows users to get mobile push notifications for changes to their ODB content.
CSOM
The mobile push notifications can be enabled using Microsoft.Online.SharePoint.TenantAdministration.Tenant property NotificationsInOneDriveForBusinessEnabled.
$spoTenant= New-Object Microsoft.Online.SharePoint.TenantAdministration.Tenant($Ctx)
$ctx.Load($spoTenant)
$ctx.ExecuteQuery()
$spoTenant.NotificationsInOneDriveForBusinessEnabled=$true
SharePoint Online Management Shell
Mobile Push Notifications can be enabled or disabled also with SharePoint Online Management Shell and the following cmdlets:
To allow:
Connect-SPOService
Set-SPOTenant -NotificationsInOneDriveForBusinessEnabled $true
To disallow:
Connect-SPOService
Set-SPOTenant -NotificationsInOneDriveForBusinessEnabled $false
Sharing Notifications
Sharing notifications inform OneDrive for Business owners when
- other users invite additional external users to shared files
- the invited users accept their invitations, or
- anonymous link is created or changed
These notifications can be modified in SharePoint Admin Center:
The three sharing notifications correspond to 3 properties of Microsoft.Online.SharePoint.TenantAdministration.Tenant object:
- NotifyOwnersWhenInvitationsAccepted enables or disables emails sent to ODB owners when external users accept invitations to access files
- NotifyOwnersWhenItemsReshared enables or disables emails sent to ODB owners when other users invite additional external users
- OwnerAnonymousNotification enables or disables emails sent to ODB owners when anonymous access link is created or changed
OwnerAnonymousNotification
CSOM
An example of how to modify the OwnerAnonymousNotification using CSOM:
#Paths to SDK
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\SharePoint Client Components\16.0\Assemblies\Microsoft.Online.SharePoint.Client.Tenant.dll"
$ctx=New-Object Microsoft.SharePoint.Client.ClientContext($url)
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password)
$ctx.ExecuteQuery()
$spoTenant= New-Object Microsoft.Online.SharePoint.TenantAdministration.Tenant($Ctx)
$ctx.Load($spoTenant)
$ctx.ExecuteQuery()
$spoTenant.NotificationsInOneDriveForBusinessEnabled =$true
$spoTenant.OwnerAnonymousNotification=$false
$ctx.Load($spoTenant)
$ctx.ExecuteQuery()
Write-Output $spoTenant
Full script Notify OneDrive for Business owner if anonymous link to their content is created is available for download from Technet Gallery.
SharePoint Online Management Shell
To enable:
Set-SPOTenant -OwnerAnonymousNotification $true
To disable:
Set-SPOTenant -OwnerAnonymousNotification $false
NotifyOwnersWhenItemsReshared
CSOM
An example below shows how to enable or disable the setting that notifies OneDrive for Business owners when other users further share the content of the owner's OneDrive:
#Paths to SDK
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\SharePoint Client Components\16.0\Assemblies\Microsoft.Online.SharePoint.Client.Tenant.dll"
$ctx=New-Object Microsoft.SharePoint.Client.ClientContext($url)
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password)
$ctx.Load($ctx.Web)
$ctx.ExecuteQuery()
$spoTenant= New-Object Microsoft.Online.SharePoint.TenantAdministration.Tenant($Ctx)
$ctx.Load($spoTenant)
$ctx.ExecuteQuery()
$spoTenant.NotifyOwnersWhenItemsReshared=$NotifyOwnersWhenItemsReshared
$ctx.Load($spoTenant)
$ctx.ExecuteQuery()
Write-Output $spoTenant
Full script Notify OneDrive for Business owner if their content is reshared is available for download from Technet Gallery.
SharePoint Online Management Shell
Set-SPOTenant -NotifyOwnersWhenItemsReshared $true
NotifyOwnersWhenInvitationsAccepted
This settings enables or disables sending emails to OneDrive for Business owners when their invitations have been accepted by external invitees.
CSOM
#Paths to SDK
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\SharePoint Client Components\16.0\Assemblies\Microsoft.Online.SharePoint.Client.Tenant.dll"
$ctx=New-Object Microsoft.SharePoint.Client.ClientContext($url)
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $password)
$ctx.Load($ctx.Web)
$ctx.ExecuteQuery()
$spoTenant= New-Object Microsoft.Online.SharePoint.TenantAdministration.Tenant($Ctx)
$ctx.Load($spoTenant)
$ctx.ExecuteQuery()
$spoTenant.NotifyOwnersWhenInvitationsAccepted=$NotifyOwnersWhenInvitationsAccepted
$ctx.Load($spoTenant)
$ctx.ExecuteQuery()
SharePoint Online Management Shell
Set-SPOTenant -NotifyOwnersWhenInvitationsAccepted $true