powershell 使用SDL Web CMS交叉检查登台网站上的XPM组件元数据。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 使用SDL Web CMS交叉检查登台网站上的XPM组件元数据。相关的知识,希望对你有一定的参考价值。

# This script loads the HTML source of a page from your staging website, scans it for XPM tags, and verifies which items are out of date.

# The url of the page you want to check
$url = "http://localhost:82/se"

Import-Module Tridion-CoreService
# Configure Core Service module if it was not already persisted
#Set-TridionCoreServiceSettings -HostName "cmshostname" -Version Web-8.1 -Credential (Get-Credential)

$source = Invoke-WebRequest $url

$ErrorActionPreference = "Stop"
$sourceComponentPresentations = ([regex]'<!-- Start Component Presentation: {"ComponentID":"([tcm:0-9/-]+)".+"ComponentModified":"([0-9T:/-]+).+"ComponentTemplateID":"([tcm:0-9/-]+)".+"ComponentTemplateModified":"([0-9T:/-]+).+}').Matches($source)

foreach ($cp in $sourceComponentPresentations)
{
    $sourceComponentId = $cp.Groups[1].Value
    [datetime] $sourceComponentModified = $cp.Groups[2].Value
    $sourceComponentTemplateId = $cp.Groups[3].Value
    [datetime] $sourceComponentTemplateModified = $cp.Groups[4].Value
    Write-Host -ForegroundColor DarkYellow ("Found in source. ComponentId: {0}, ComponentModified: {1}, ComponentTemplateId: {2}, ComponentTemplateModified: {3}" -f $sourceComponentId, $sourceComponentModified, $sourceComponentTemplateId, $sourceComponentTemplateModified) 

    $item = (Get-TridionItem $sourceComponentId)
    [datetime] $cmsComponentModified = $item.VersionInfo.RevisionDate
    $cmsComponentModified = $cmsComponentModified.AddMilliseconds(-$cmsComponentModified.Millisecond) # set miliseconds to 0
    $cmsComponentTitle = $item.Title
    Write-Host -ForegroundColor DarkYellow ("Found in CMS: ComponentId: {0}, ComponentModified: {1}" -f $sourceComponentId, $cmsComponentModified) 

    $item = (Get-TridionItem $sourceComponentTemplateId)
    [datetime] $cmsComponentTemplateModified = $item.VersionInfo.RevisionDate
    $cmsComponentTemplateModified = $cmsComponentTemplateModified.AddMilliseconds(-$cmsComponentTemplateModified.Millisecond) # set miliseconds to 0
    $cmsComponentTemplateTitle = $item.Title
    Write-Host -ForegroundColor DarkYellow ("Found in CMS: ComponentTemplateId: {0}, ComponentTemplateModified: {1}" -f $sourceComponentTemplateId, $cmsComponentTemplateModified) 

    Write-Host -ForegroundColor DarkYellow ("soure and CMS component modified dates match: {0}" -f ($sourceComponentModified -eq $cmsComponentModified))
    Write-Host -ForegroundColor DarkYellow ("soure and CMS component template modified dates match: {0}" -f ($sourceComponentTemplateModified -eq $cmsComponentTemplateModified))
    
    if(($sourceComponentModified -ne $cmsComponentModified) -or ($sourceComponentTemplateModified -ne $cmsComponentTemplateModified))
    {
        
        Write-Host ("Component Presentation not in sync! ComponentId: {0}, ComponentTemplateId: {1}" -f $sourceComponentId, $sourceComponentTemplateId) 
        Write-Host ("Component: {0}" -f $cmsComponentTitle) 
        Write-Host ("ComponentTemplate: {0}" -f $cmsComponentTemplateTitle) 
        Write-Host ("Found in source. ComponentId: {0}, source component modified: {1}, CMS component modified: {2}" -f $sourceComponentId, $sourceComponentModified, $cmsComponentModified) 
        Write-Host ("Found in source. ComponentTemplateId: {0}, source component modified: {1}, CMS component modified: {2}" -f $sourceComponentTemplateId, $sourceComponentTemplateModified, $cmsComponentTemplateModified) 
    }
}

以上是关于powershell 使用SDL Web CMS交叉检查登台网站上的XPM组件元数据。的主要内容,如果未能解决你的问题,请参考以下文章

powershell 使用PowerShell将SDL Web组件与模式同步

powershell 使用PowerShell将SDL Web组件与模式同步

powershell 使用PowerShell将SDL Web组件与模式同步

powershell 使用PowerShell将SDL Web组件与模式同步

powershell 使用SDL Web核心服务编辑组件

powershell 使用SDL Web核心服务编辑组件