我创建了一个报表,如果我从PowerShellISE手动运行它,它会生成我期望的项目列表,但是当我从报表工具运行它时,它不会返回任何结果。
这个脚本会抓取所有的项目版本和语言,大约有80000个项目,这需要一段时间。
在生成所有项的列表或任何其他解决方法之前,是否有方法添加延迟?
源代码:
$RichTextContentID = "";
$internalLinkPattern = '<a href="~\/link\.aspx\?_id=(?<sitecoreid>[a-zA-Z\d]{32})&_z=z">';
$literatureTemplate = "";
$global:guiltyItems = @();
function Process-RichText
{
param( [Parameter(Mandatory = $true)] [Sitecore.Data.Fields.Field]$field,
[Parameter(Mandatory = $true)] [string]$pattern,
[Parameter(Mandatory = $true)] [Sitecore.Data.Items.Item]$item)
$allMatches = [System.Text.RegularExpressions.Regex]::Matches($field.Value,$pattern);
foreach ($match in $allMatches)
{
$currentItem = Get-Item master -Id ([Sitecore.Data.ID]::Parse($match.Groups["sitecoreid"].Value)).Guid;
if ($currentItem.Template.Id -eq $literatureTemplate)
{
if ($global:guiltyItems -notcontains $item)
{
$global:guiltyItems += $item;
}
}
}
}
$allitems = Get-Item master -Query "/sitecore/content/MyWebsiteTree//*" -Language * -Version *;
foreach ($item in $allItems) {
foreach ($field in $item.Fields)
{
if ($field.Id -eq $RichTextContentID -and ($field.Value -match $internalLinkPattern))
{
Process-RichText $field $internalLinkPattern $item;
}
}
}
if ($global:guiltyItems.Count -eq 0) {
Show-Alert "Did not find any items to match your condition.";
}
else {
$props = @{
Title = ""
InfoDescription = ""
PageSize = 50
};
($global:guiltyItems) |
Show-ListView @props -Property @{ Label="Item name"; Expression={$_.Name}; },
@{ Label="ID"; Expression={$_.ID}; },
@{ Label="Display name"; Expression={$_.DisplayName}; },
@{ Label="Language"; Expression={$_.Language}; },
@{ Label="Version"; Expression={$_.Version}; },
@{ Label="Path"; Expression={$_.ItemPath}; },
@{ Label="Created"; Expression={$_.__Created}; },
@{ Label="Created by"; Expression={$_."__Created by"}; },
@{ Label="Updated"; Expression={$_.__Updated}; },
@{ Label="Updated by"; Expression={$_."__Updated by"}; }
}
Close-Window;
谢谢
le:object$all items需要一段时间来填充,SiteCore客户机不会等待后端读取所有项目,因此生成报告时,$global:guityitems始终为空。