Skip to content

Instantly share code, notes, and snippets.

@strezag
Last active September 8, 2023 17:12
Show Gist options
  • Save strezag/5e98910f887e0d4224f12352b5b9de24 to your computer and use it in GitHub Desktop.
Save strezag/5e98910f887e0d4224f12352b5b9de24 to your computer and use it in GitHub Desktop.
function Get-LinkFieldUrl {
[CmdletBinding()]
param(
[Parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true)]
[ValidateNotNullOrEmpty()]
[Sitecore.Data.Items.Item]$Item
)
# Regular expression to extract the URL
$regex = '<link\s+url="([^"]+)"'
$linkFieldValue = $Item.Fields["My Link Field"].Value;
if ($linkFieldValue -ne "") {
if ($linkFieldValue -match $regex) {
$urlValue = $matches[1]
return $urlValue
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment