首页 > 解决方案 > 使用 -TakeSourcePageName 时不会重命名现代页面

问题描述

问题区域 [ ] 页面转换:使用 PnP PowerShell 中的页面转换时出错

预期或期望的行为 发布执行脚本我期待经典页面在将参数 (-TakeSourcePageName) 设置为 true 后预计将重命名为“Previous_Pagename.aspx”,而现代页面将重命名为“Pagename.aspx”

Observed Behavior Classic 页面在转换后仍为旧文件名“Home.aspx”,现代页面为“Migrated_Home.aspx”

重现步骤 [我正在尝试为整个站点页面库执行页面转换脚本。第 1 步:输入站点 URL 第 2 步:输入参数 (-TakeSourcePageName) 的值作为 Previous 或 Old

非常感谢你。您的帮助将不胜感激。]

#PSScript 用于页面转换

[CmdletBinding()]
param (

    [Parameter(Mandatory = $true, HelpMessage = "Url of the site containing the pages to modernize")]
    [string]$SourceUrl,

    [Parameter(Mandatory = $true, HelpMessage = "Modern page takes source page name")]
    [bool]$TakeSourcePageName = $true,    

    [Parameter(Mandatory = $false, HelpMessage = "Supply credentials for multiple runs/sites")]
    [PSCredential]$Credentials,

    [Parameter(Mandatory = $false, HelpMessage = "Specify log file location, defaults to the same folder as the script is in")]
    [string]$LogOutputFolder = $(Get-Location)
)
begin
{
    Write-Host "Connecting to " $SourceUrl
    
    if($Credentials)
    {
        Connect-PnPOnline -Url $SourceUrl -Credentials $Credentials
        Start-Sleep -s 3
    }
    else
    {
        Connect-PnPOnline -Url $sourceUrl -Interactive
        Start-Sleep -s 3
    }
}
process 
{    
    Write-Host "Ensure the modern page feature is enabled..." -ForegroundColor Green
    Enable-PnPFeature -Identity "B6917CB1-93A0-4B97-A84D-7CF49975D4EC" -Scope Web -Force

    Write-Host "Modernizing wiki and web part pages..." -ForegroundColor Green
    # Get all the pages in the site pages library. 
    # Use paging (-PageSize parameter) to ensure the query works when there are more than 5000 items in the list
    $pages = Get-PnPListItem -List sitepages -PageSize 500 -Query "<Query><Where><Neq><FieldRef Name='ContentType' /><Value Type='Computed'>Folder</Value></Neq></Where></Query>"

    Write-Host "Pages are fetched, let's start the modernization..." -ForegroundColor Green
    Foreach($page in $pages)
    { 
        $pageName = $page.FieldValues["FileLeafRef"]
        
        if ($page.FieldValues["ClientSideApplicationId"] -eq "b6917cb1-93a0-4b97-a84d-7cf49975d4ec" ) 
        { 
            Write-Host "Page " $page.FieldValues["FileLeafRef"] " is modern, no need to modernize it again" -ForegroundColor Yellow
        } 
        else 
        {
           Write-Host "Processing page: $($pageName)" -ForegroundColor Cyan
          ConvertTo-PnPPage -Identity $page.FieldValues["ID"] ` -Overwrite ` -TakeSourcePageName: $TakeSourcePageName ` -LogType File ` -LogFolder $LogOutputFolder ` -KeepPageCreationModificationInformation ` -CopyPageMetadata ` -SkipItemLevelPermissionCopyToClientSidePage
           
        }
    }

    # Write the logs to the folder
    Write-Host "Writing the conversion log file..." $LogOutputFolder -ForegroundColor Green
    Save-PnPPageConversionLog

    Write-Host "Wiki and web part page modernization complete! :)" -ForegroundColor Green
}
end
{
    Disconnect-PnPOnline
}

标签: powershellsharepoint-onlinepnp-js

解决方案


推荐阅读