Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll'
- Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll'
- function CreateWikiPage()
- {
- [CmdletBinding()]
- param(
- [Parameter(Mandatory=$true)][string]$webUrl,
- [Parameter(Mandatory=$false)][System.Net.NetworkCredential]$credentials,
- [Parameter(Mandatory=$true)][string]$pageName,
- [Parameter(Mandatory=$true)][string]$pageContent,
- [Parameter(Mandatory=$false)][string]$XmlInput
- )
- $templateRedirectionPageMarkup = '<%@ Page Inherits="Microsoft.SharePoint.Publishing.TemplateRedirectionPage,Microsoft.SharePoint.Publishing,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %> <%@ Reference VirtualPath="~TemplatePageUrl" %> <%@ Reference VirtualPath="~masterurl/custom.master" %>';
- $credentials = New-Object System.Net.NetworkCredential('***', '***')
- $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($webUrl)
- $ctx.Credentials = $credentials
- $wikiPages = $ctx.Web.Lists.GetByTitle("Pages")
- $load = [Microsoft.SharePoint.Client.ClientContext].GetMethod("Load")
- $listLoad = $load.MakeGenericMethod([Microsoft.SharePoint.Client.List])
- $listLoad.Invoke($ctx,@($wikiPages,$null))
- $ctx.ExecuteQuery()
- $file = New-Object Microsoft.SharePoint.Client.FileCreationInformation
- $file.Url = $pageName+='.aspx'
- $file.Content = [System.Text.Encoding]::UTF8.GetBytes($templateRedirectionPageMarkup)
- $file.Overwrite = $true
- $wikiFile = $wikiPages.RootFolder.Files.Add($file)
- $fileLoad = $load.MakeGenericMethod([Microsoft.SharePoint.Client.File])
- $fileLoad.Invoke($ctx,@($wikiFile,$null))
- $wikiPage = $wikiFile.ListItemAllFields
- $wikiPage["PublishingPageContent"] = $pageContent
- $wikiPage["PublishingPageLayout"] = "/sites/testWiki/_catalogs/masterpage/CustomWiki.aspx, CustomWiki"
- $wikiPage.Update()
- $ctx.ExecuteQuery();
- }
- [xml]$pagesXML = Get-Content F:\BoggleMigration\BoggleData.xml
- if ($pagesXML -eq $null) { return }
- $webUrl='http://infostore/sites/testwiki'
- $pagesXML.Pages.Page | ForEach-Object {
- $credentials = New-Object System.Net.NetworkCredential('username', 'password','url')
- $PageName = [string]$_.Title
- write-host 'page name: ' $PageName.Title
- $PageContent = [string]$_.Content
- write-host 'content: ' $PageContent|Get-Member
- CreateWikiPage $webUrl $credentials $pageName $pageContent
- Write-Host "Creating " $PageName
- } #End ForEach Loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement