Created
June 4, 2020 15:11
-
-
Save netojoa/ff2eb6d547df6ab16eac3ff40950a265 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$script:siteName = "website" | |
$script:language = @("az-AZ","de-DE","en","en-ASIA","en-AU","en-CA","en-CENTAFR","en-EASTAFR","en-FJ","en-GB","en-IE","en-IN","en-JP","en-MIDEAST","en-NORTHAFR","en-NZ","en-PG","en-RU","en-SG","en-SOLUTION","en-US","en-WESTAFR","en-ZA","es-CO","es-ES","es-MX","fr-BE","fr-FR","id-ID","it-IT","ja-JP","kk-KZ","ko-KR","ms-MY-ML-Malay","nb-NO","nl-BE","nl-NL","pl-PL","pt-BR","pt-PT","ro-RO","ru-AZ","ru-KZ","ru-RU","sv-SE","zh-CN","uk-UA") | |
$script:startPath = "/sitecore/content/Company/Home" | |
$script:links = @() | |
$script:csvPath = "$SitecoreDataFolder\links.csv" | |
$script:database = "web" | |
Get-Item -Path $script:csvPath | Remove-Item -Force -Permanently | |
function HasLayout($item) { | |
if($item) { | |
$result = $item | Get-Layout | |
if ($result) { return $true } | |
else { return $false } | |
} else { return $false } | |
} | |
function Get-ItemUrl($item, $siteName) { | |
$siteContext = [Sitecore.Sites.SiteContext]::GetSite($siteName) | |
$urlOptions = New-Object ([Sitecore.Links.UrlOptions]::DefaultOptions) | |
$urlOptions.AddAspxExtension = $false | |
$urlOptions.AlwaysIncludeServerUrl = $true | |
$urlOptions.Site = $siteContext | |
$urlOptions.Language = $item.Language | |
$urlOptions.SiteResolving = $true | |
$urlOptions.EncodeNames = $true | |
$urlOptions.LowercaseUrls = $true | |
$result = New-UsingBlock(New-Object Sitecore.Sites.SiteContextSwitcher $siteContext) { | |
New-UsingBlock(New-Object Sitecore.Data.DatabaseSwitcher $item.Database) { | |
New-UsingBlock(New-Object Sitecore.Globalization.LanguageSwitcher $item.Language) { | |
[Sitecore.Links.LinkManager]::GetItemUrl($item, $urlOptions) | |
} | |
} | |
} | |
$linkUrl = $result[0][0] | |
return ($linkUrl) | |
} | |
function Run() { | |
$criteria = @() | |
$criteria = @( | |
@{ Filter = "StartsWith"; Field = "_fullpath"; Value = $script:startPath }, | |
@{ Filter = "ContainsAny"; Field = "_language"; Value = $script:language } | |
) | |
$props = @{ | |
Index = "sitecore_web_index" | |
Criteria = $criteria | |
} | |
Find-Item @props | ForEach-Object { | |
$web = [Sitecore.Configuration.Factory]::GetDatabase($script:database) | |
$language = [Sitecore.Globalization.Language]::Parse($_.Language) | |
$item = $web.GetItem($_.ItemId, $language) | |
if (HasLayout($item)) { | |
$linkUrl = Get-ItemUrl -Item $item -SiteName $siteName | |
$script:links += New-Object PSObject -Property @{ IsFallback = $item.IsFallback; Url = $linkUrl; Name = $item.Name; Database = $item.Database; Path = $_.path; Version = $item.Version; Language = $item.Language; Created = $item.Created; Modified = $_.Updated; "Modified by" = $_.UpdatedBy } | |
} | |
} | |
$script:links | Export-Csv -Path $script:csvPath -NoTypeInformation -Append | |
Get-Item -Path $script:csvPath | Out-Download | |
} | |
Run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment