kwizcom banner advertisement

SharePoint Online: Create a WIKI Page using PowerShell

Requirement: Create a wiki page in SharePoint Online using PowerShell

SharePoint Online: Create WIKI Page using PowerShell CSOM
#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://crescenttech.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 wiki page in the given URL.

Create wiki page in SharePoint Online using PnP PowerShell
#Config Variable
$SiteURL = "https://crescenttech.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 
SharePoint Online: Create a WIKI Page using PowerShell SharePoint Online: Create a WIKI Page using PowerShell Reviewed by Salaudeen Rajack on March 14, 2018 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.