Tag: sharepoint online

Office 365 Advent Calendar – 23 Bulk-updating File Extensions in SharePoint Online with PowerShell



A short while ago, I had to update a fairly large number of documents in multiple libraries in a SharePoint Online site. Problem was that their file extension was .html which doesn’t display in the browser if stored in SharePoint Online, but rather these files get downloaded upon opening. The workaround – rename them to .aspx. The following scripts does this for all .html files and renames them to .aspx


$cred = Get-Credential
Connect-PnPOnline -Url "http://mytenant.sharepoint.com/sites/demo" -Credentials $cred
$ctx = Get-PnPContext
$libraries = Get-PnPlist | Where{$_.BaseTemplate -eq 101}
foreach($lib in $libraries) {
	write-host "Getting items from $($lib.Title)"
	$items = Get-PnPListItem -List $lib -Fields "Title", "FileLeafRef" | where {$_["FileLeafRef"] -like "*.html"}
	write-host "Looping through the items"
	foreach($item in $items) {
		$file = $item.File
		write-host "Renaming file $($file.Name)"
		$newName = $file.Name -Replace "\.html",".aspx"
		Move-PnPFile -ServerRelativeUrl $file.ServerRelativeUrl -TargetUrl "$($file.ListItemAllFields['FileDirRef'])/$($newName)" -Force

Office 365 Advent Calendar – 22 Modern and Classic Experience in SharePoint Online


Earlier this year, Microsoft announced and rolled out the modern experience for lists. They didn’t stop at that, but also introduced modern pages and sites. But what are the differences to the ‘classic experiences’, so the type of lists, libraries, pages, and sites that we’ve been using now for many years? How can you switch between these two experiences? And how can you customise the modern experience items? Luckily, there’s some good guidance available from Microsoft.

First of all, it should be noted that the classic experience won’t disappear anytime soon. While Microsoft is rolling out the modern experience, the classic experience will still remain available. However, it should be noted that the functionality set between these two can be quite different. Review the links listed further below for details.

How do I switch between experiences?

For lists and libraries, please have a look at Switch the default experience for lists or document libraries from new or classic.

For modern sites and pages, the situation is a bit more different. You can’t switch a site between the classic and the modern experience. You also can’t upgrade a ‘classic’ site to a ‘modern’ site, however you can enable the corresponding capabilities to make a ‘classic’ site make use of the ‘modern’ features.


What are the differences between ‘classic’ and ‘modern’ lists/libraries?

This article provides some details on which functionality is currently only available in the ‘classic experience’. As you can see, there is quite a range of useful functionality that is not yet in the ‘modern experience’. Note that not all differences are listed. For example, the new smart filters are only available in modern lists. Also, existing customizations will most likely not work anymore.


What kind of customization possibilities do I have for ‘modern experiences’?

Have a look at this great article by Vesa Juvonen, and the other pages mentioned in it.


Office 365 Advent Calendar – 21 Get all Instances of a Web Part in a SharePoint Online Site



Sometimes you may need to figure out where a specific type of web part has been used. Today, I’ll show you how you can check all pages in your Site Pages library for a specific web part.

I’ve had this code for a while as I was looking for some specific web parts (Content Editor) before. Yesterday, I briefly saw a blog post on dev.office.com announcing the deprecation of the Visio Web Access web part on SharePoint Online (as Visio Online is coming!), though that blog post has disappeared again (I suspect we’ll see it again soon). So I decided to modify it slightly to look for all instances of Visio Web Access web parts and save the results to a CSV file.


The following code checks all pages in the given site’s Site Pages library for instance of the ‘Visio Web Access’ web part. You could easily modify it to loop through all sites in a site collection, or even all sites within your whole tenant.

$cred = Get-Credential
Connect-PnPOnline -Url https://mytenant.sharepoint.com/sites/pagestest -Credentials $cred

$visioWebParts = @()

$ctx = Get-PnPContext
$lists = (Get-PnPWeb).Lists
#Note: I'm not accessing the Site Pages library by URL or title, as I had sites in different languages
$sitePages = $lists.EnsureSitePagesLibrary()

$pages = Get-PnPListItem -List $sitePages[0].Id
foreach($page in $pages) {
	$webparts = Get-PnPWebPart -ServerRelativePageUrl $page.File.ServerRelativeUrl
	foreach($webpart in $webparts) {
		$wpxml = Get-PnPWebPartXml -ServerRelativePageUrl $page.File.ServerRelativeUrl -Identity $webpart.Id
		# The Visio Web Access part is referenced in the XML definition of the web part
		# with type Microsoft.Office.Visio.Server.WebControls.VisioWebAccess. Change this for
		# any other types of web parts you want to find 
		if($wpxml -Match '<type name="Microsoft.Office.Visio.Server.WebControls.VisioWebAccess,') {
			$visioWebParts += New-Object PSObject -Property @{
				'PageUrl' = $page.File.ServerRelativeUrl
				'WebPartTitle' = $webpart.WebPart.Title

$visioWebParts | select PageUrl, WebPartTitle | Export-Csv C:\visio.csv

Office 365 Advent Calendar – 20 Get notified about new SharePoint Online Site Collection Administrators


If your organization provides business users with the possibility to manage sites themselves by assigning them site collection administrator rights, you may want to know if they add anyone else as site collection administrator. While you could run a script regularly to retrieve a list of all site collection administrators on all sites and then compare this data with previous information, there is also an alternative that you can use. Office 365 provides you with the option to get alerted when someone gets added as a site collection administrator.

First, open the Office 365 Security & Compliance portal. Select Alerts and ‘Manage alerts’, then click on ‘Add an alert’ in the right content pane


Setting up the alert is fairly easy. Start by specifying a name and optionally a description. The most important setting is “Send this alert when…” where you specify which activities you want to get alerted on. Select ‘Added site collection admin’ here. Sadly, there is no way to monitor removal of site collection admins.

Lastly, specify who should be alerted, and save your alert.

Please note the following: “It can take up to 30 minutes or up to 24 hours after an event occurs for the corresponding audit log entry to be displayed in the search results.” (Search the audit log in the Office 365 Security & Compliance Center). This means that notifications are not immediate, but may take some time until the corresponding event appears in the audit logs and the alert gets triggered.

Office 365 Advent Calendar – 15 Activating Publishing Features on SharePoint Online Sites with PowerShell



Activating SharePoint’s Publishing features can easily be done on a single site collection or site. But what if you need to activate Publishing on a hierarchy of subsites, or across multiple site collections?


Once again, we’re using the PnP PowerShell cmdlets.

First some basics. The ‘main’ feature to activate is the PublishingSite feature on the Site Collection level. After you connected to a site collection (Connect-PnPOnline), you can activate it as follows:

Enable-PnPFeature -Identity f6924d36-2fa8-4f0b-b16d-06b7250180fa -Scope Site

The -Scope Site parameter is important, as the default for this parameter is set to Web, and the feature wouldn’t get activated without specifying it correctly.

Once that’s done, we can activate the PublishingWeb feature for the current site (on a Web scope):

Enable-PnPFeature -Identity 94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb

Office 365 Advent Calendar – 14 Exporting SharePoint Online List/Library Details


Well, this is a bit embarrassing. Yesterday, for the first time, I didn’t verify if my scheduled blog post got published properly. And yesterday, also for the first time, it didn’t get published. I made a small scheduling mistake (it’s not 2017 yet…), so the 14th December post comes a day late:


From time to time you may need an overview of all lists and libraries in your site together with the number of items in each list/library, and when an item in it was last modified. You can easily see this information from the Site Contents page:

But there are times when this information needs to be available in Excel, which is what I’ll show you today how to retrieve:


$cred = Get-Credential
Connect-PnPOnline -Url "https://mytenant.sharepoint.com/sites/demo" -Credentials $cred

#the following is required to load the corresponding list templates for each list/library
$ctx = Get-PnPContext
$templates = (Get-PnPWeb).ListTemplates

Get-PnPList | select Title, @{label="Url";Expression={$_.RootFolder.ServerRelativeUrl}},`
@{label="Type";Expression={$bt=$_.BaseTemplate;$templates |`
Where{$_.ListTemplateTypeKind -eq $bt} | foreach{$_.Name}}},`
ItemCount, LastItemModifiedDate | Export-Csv c:\ListInfo.csv

And here’s the output from the script:


Office 365 Advent Calendar – 11 Adding sample items with random data to a SharePoint Online List



Sometimes you want to create some random sample data to be used in a SharePoint Online list. For example, in yesterday’s post I was using a list with some data which I entered manually, but I thought afterwards that I could’ve scripted it to create many more items in my demo list. Today, I show you how you can easily fill a list in SharePoint Online with as many sample items as you need, all with random values based on some predefined arrays.


The code below requires a few things from you:

  1. You need to define the number of items you want to create
  2. You need to define a few arrays with potential values for each of your columns (in my case, $Company, $Region, and $Product)
  3. You need to define the list where you want to add those items to
  4. Lastly, you need to update the -Values parameter with the correct column names for your list
$itemsToGenerate = 10
$listName = "Sales Pipeline"

# Sample data for the list
$Company = ("Ah Loong Pte Ltd", "Contoso Inc", "Fabrikam Corp", "Flowers by Irene",`
 "NorthSouth Trading Inc", "Petrox Oil Company", "Spacely Sprockets", "The Frying Dutchman")
$Region = ("North", "East", "South", "West")
$Product = ("Admin ToolKit", "EZClean", "WonderTool 2000", "Business Process WonderKit")

$cred = Get-Credential
Connect-PnPOnline -Url https://mytenant.sharepoint.com/sites/demo -Credentials $cred

foreach($i in 1..$itemsToGenerate) {
	#Update the -Values below with the correct column names from your list
	Add-PnPListItem -List $listName -Values @{`
		# I'm assigning a randomly chosen value from the $Company array to the item column
		"Title" = $Company[(Get-Random -Minimum 0 -Maximum ($Company.Count))];`
		"Region" = $Region[(Get-Random -Minimum 0 -Maximum ($Region.Count))];`
		"Product" = $Product[(Get-Random -Minimum 0 -Maximum ($Product.Count))];`
		# Here, I want to create a random number between 150 and 99999
		"Potential_x0020_Value" = (Get-Random -Minimum 150 -Maximum 99999);}

Office 365 Advent Calendar – 10 SmartFilters and Grouping in SharePoint Online Modern Lists


Microsoft has just started rolling out a new feature called Smart Filters to SharePoint Online tenants with First Release enabled, all tenants will see it in January. Smart Filters are available in Modern Lists, and allow you to filter from a sidebar pane to easily and quickly find items you’re looking for.

What’s the difference to the existing filtering functionality on columns? Smart Filters are not just shown for a single column, but for all supported columns in the current view, so that you can easily filter your data from a single pane. However, not all types of columns can be filtered. In the recording below, the column ‘Company’ is a ‘Single Line of Text’ column, which currently can’t be used. I suspect that we will see some improvements here soon. Lastly, once you’ve found a nice set of filters that you find useful, you can save them as a new View.


The nice thing about Smart Filters is that they also work with the new Grouping functionality in Modern Lists. You can use both of them at the same time to drill down into your data and hopefully gain some valuable insights: