SharePoint Online: Create a WIKI Page using PowerShell

Requirement: Create a wiki page in SharePoint Online using PowerShell.

How to create a wiki page in SharePoint Online?

Wiki pages in SharePoint Online are web pages that can be easily created and edited using the browser-based interface. They are designed to facilitate collaboration and knowledge sharing within an organization. If you want to create text content with images, A wiki page is perfect for that purpose. One of the key benefits of using wiki pages in SharePoint Online is the ease of collaboration. Multiple users can edit the same page simultaneously, and changes are automatically saved and versioned. It is quick and easy to create wiki pages in SharePoint Online.

Here is how you can create a simple wiki page in SharePoint Online:

  1. Go to your SharePoint Online site >> Click on the setting gear and then navigate to the “Site Contents” page
  2. Click on New >> and choose the “wiki page” option among the three. how to create a wiki page in sharepoint onlinehow to create a wiki page in sharepoint online
  3. Enter a name for your wiki page and click on create.

Now that your wiki page has been created, you can type/copy-paste anything on your page, as with other wiki page editors. Once done, you can save your page.

SharePoint Online: Create WIKI Page using PowerShell CSOM

To automate wiki page creation, we can use PowerShell as below:

#Load SharePoint CSOM Assemblies
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\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Config Variable
$SiteURL = "https://crescent.sharepoint.com/Sites/Marketing"
$PageRelativeURL="/sites/Marketing/Wiki/Knowledgebase.aspx"
$PageContent="A KEDB is a database of all such known errors, recorded as they are and when they happened - and they're maintained over time."

#Get Credentials to connect
$Cred= Get-Credential
 
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

#Create a Wiki page
$WikiPageInfo = New-Object Microsoft.SharePoint.Client.Utilities.WikiPageCreationInformation
$WikiPageInfo.WikiHtmlContent = $PageContent
$WikiPageInfo.ServerRelativeUrl = $PageRelativeURL
$WikiFile = [Microsoft.SharePoint.Client.Utilities.Utility]::CreateWikiPageInContextWeb($Ctx, $WikiPageInfo)
$Ctx.ExecuteQuery()

This PowerShell adds a wiki page in the given URL.

Create a wiki page in SharePoint Online using PnP PowerShell

To create a new wiki page in a SharePoint Online site using PnP PowerShell, you can use the cmdlet Add-PnPWikiPage

#Config Variable
$SiteURL = "https://crescent.sharepoint.com/Sites/Marketing"
$PageRelativeURL="/sites/Marketing/Wiki/Knowledgebase.aspx"
$PageContent="A KEDB is a database of all such known errors, recorded as they are and when they happened - and they're maintained over time."

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Create a Wiki page
Add-PnPWikiPage -ServerRelativePageUrl $PageRelativeURL -Content $PageContent 

In summary, wiki pages are a powerful tool for collaboration and knowledge sharing in SharePoint Online. Creating a wiki page in SharePoint Online is a straightforward process that can be accomplished using the web browser interface or PowerShell. By using the SharePoint Online PnP PowerShell module, you can easily create wiki pages on your SharePoint Online site. Whether you are documenting processes, procedures, or other important information, wiki pages are a great way to collaborate and share information with your team.