来自不同Wiki列表的Powershell复制Sharepoint Wiki页面-sharepoint-pnp

时间:2018-10-23 15:41:29

标签: powershell sharepoint

我正在使用sharepoint-pnp模块,但是它似乎缺少我先前构建的功能,我想知道我是否在这里缺少什么。

问题是,我在顶部有几个Web部件和一个过滤器,以使我的Wiki的重新部署更加简单。我可以更改模板,它将重建所有页面并自动更新过滤器标志。

这是我正在使用的复制代码:

function Get-SharepointContext
{
    Param(
        [Parameter(Mandatory=$true)]
        $siteUrl,
        [Parameter(Mandatory=$false)]
        $cred)

    If(!$cred){$cred = get-credential -UserName "$ENV:Username@$env:USERDNSDOMAIN" -Message "Login"}

    [string]$username = $cred.UserName
    $securePassword = $cred.Password

    [Void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
    $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
    $ctx.RequestTimeOut = 1000 * 60 * 10;
    $ctx.AuthenticationMode =[Microsoft.SharePoint.Client.ClientAuthenticationMode]::Default
    $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword)
    $ctx.Credentials = $credentials
    Return $ctx
}
function Get-AuthenticationCookie($context)
{
    $sharePointUri = New-Object System.Uri($context.site.Url)
    $authCookie = $context.Credentials.GetAuthenticationCookie($sharePointUri)
    if($? -eq $false) #https://ss64.com/ps/syntax-automatic-variables.html
    {
        return $null
    }
    $fedAuthString = $authCookie.TrimStart("SPOIDCRL=".ToCharArray())
    $cookieContainer = New-Object System.Net.CookieContainer
    $cookieContainer.Add($sharePointUri,(New-Object System.Net.Cookie("SPOIDCRL", $fedAuthString)))
    return $cookieContainer
}

function Copy-SharepointPage
{
    Param(
        [Parameter(Mandatory=$true)]
        $context,
        [Parameter(Mandatory=$true)]
        $sitename,
        [Parameter(Mandatory=$true)]
        $sourcePage,
        [Parameter(Mandatory=$true)]
        $destPage)

    Write-Host "Copy page $sourcePage to $destPage on " $context.web.Url  -foregroundcolor Yellow

    $requestUrl = $context.web.Url + "/_vti_bin/_vti_aut/author.dll"
    $request = $context.WebRequestExecutorFactory.CreateWebRequestExecutor($context, $requestUrl).WebRequest
    $request.Method = "POST"
    $request.Headers.Add("Content", "application/x-vermeer-urlencoded")
    $request.Headers.Add("X-Vermeer-Content-Type","application/x-vermeer-urlencoded")
    $request.UserAgent = "FrontPage"
    $request.UseDefaultCredentials = $false
    $cookiesContainer = Get-AuthenticationCookie -context $context
    $request.CookieContainer = $cookiesContainer

    $rpcCallString =
        "method=move+document%3a15%2e0%2e0%2e4569&service%5fname=" +
        "$([System.Web.HttpUtility]::UrlEncode($sitename))&oldUrl=" +
        "$([System.Web.HttpUtility]::UrlEncode($sourcePage))&newUrl=" +
        "$([System.Web.HttpUtility]::UrlEncode($destPage))&url%5flist=" +
        "%5b%5d&rename%5foption=nochangeall&put%5foption=edit&docopy=true"
    $requestStream = $request.GetRequestStream()
    $rpcHeader = [System.Text.Encoding]::UTF8.GetBytes($rpcCallString)
    $requestStream.Write($rpcHeader, 0, $rpcHeader.Length);
    $requestStream.Close();
    $response = $request.GetResponse()
    $stream = $response.GetResponseStream()
    $reader = New-Object System.IO.StreamReader($stream)
    $content = $reader.ReadToEnd()
    $reader.Close()
    $reader.Dispose()
    Write-Host "`tPage is successfully copied" -foregroundcolor green
}

当我尝试使用sharepoint-pnp模块命令获取get-pnpwikipagecontent时,它会删除Web部件并只保留模板中的标题

我一直在鬼混,我能够从模板和内容(仅仅是标题)中获取所有的webpart:

 Get-PnPWebPart -PageUrl '/sites/New%20Client%20Template/ClientTemplateFull.aspx'
 Get-PnPWikiPageContent -ServerRelativePageUrl '/sites/New%20Client%20Template/ClientTemplateFull.aspx'

但是我不知道如何将它们传送到Add-PNPWikiPage。

有人可以为此指出正确的方向吗?

0 个答案:

没有答案