Skip to main content
deleted 60 characters in body
Source Link

You can achieve it using RegEx as well  - First, you need to get the item, and then from the item, you need to get the field value. here below example will work fine for a single item but if you need it for multiple items you need to perform a loop, for example, getting children of a root item.

$anchorTagPattern = '(?is)<a[^>]*>(.*?)<\/a>'; 

$hrefPattern = '(?is)href=\"[^>]*(.*?)\"';
#You can get Html
#get contentitem fromby item field
#$htmlContent =id $itemi.Fields["Your Rich Text Contente Field"].Value;{BB87FEE6-E4CF-4D86-986B-2D1B297A081F}
$htmlContent$item = @"
<div class="test">
Get-Item -Path "master:" <div-ID class="test">"{BB87FEE6-E4CF-4D86-986B-2D1B297A081F}"
    <blockquote>hello<br />
      #get field <spanvalue class="test">hello</span>
by field name i.e </blockquote>Content
   $htmlContent <a= href="test$item.com">test</a>
  </div>
</div>Fields["Content"].Value;
"@;
$anchorTagPatternMatches = [regex]::Matches($htmlContent,  
$anchorTagPattern);

if(![string]::IsNullOrEmpty($anchorTagPatternMatches)) {
    write-host
    $anchorTagPatternMatches | ForEach-Object {
        $anchorText = $anchorTagPatternMatches[0]$_.Groups[1].Value;
        $anchorTag = $anchorTagPatternMatches[0]$_[0].Value;
        write-host $anchorTag
        write-host $anchorText
    if(![string]::IsNullOrEmpty($anchorTag)){   
        $hrefPatternMatches = [regex]::Matches($anchorTag, $hrefPattern);
        $href = $hrefPatternMatches[0].Value;
        $href = $href.Replace('href=','');
        write-host $href
        }
    }
    
}

You can achieve it using RegEx as well  -

$anchorTagPattern = '(?is)<a[^>]*>(.*?)<\/a>';
$hrefPattern = '(?is)href=\"[^>]*(.*?)\"';
#You can get Html content from item field
#$htmlContent = $item.Fields["Your Rich Text Content Field"].Value;
$htmlContent = @"
<div class="test">
   <div class="test">
    <blockquote>hello<br />
        <span class="test">hello</span>
    </blockquote>
    <a href="test.com">test</a>
  </div>
</div>
"@;
$anchorTagPatternMatches = [regex]::Matches($htmlContent, $anchorTagPattern);

if(![string]::IsNullOrEmpty($anchorTagPatternMatches)) {
    write-host $anchorTagPatternMatches
    $anchorText = $anchorTagPatternMatches[0].Groups[1].Value;
    $anchorTag = $anchorTagPatternMatches[0].Value;
    write-host $anchorText
    if(![string]::IsNullOrEmpty($anchorTag)){   
        $hrefPatternMatches = [regex]::Matches($anchorTag, $hrefPattern);
        $href = $hrefPatternMatches[0].Value;
        $href = $href.Replace('href=','');
        write-host $href
        }
}

You can achieve it using RegEx as well- First, you need to get the item, and then from the item, you need to get the field value. here below example will work fine for a single item but if you need it for multiple items you need to perform a loop, for example, getting children of a root item.

$anchorTagPattern = '(?is)<a[^>]*>(.*?)<\/a>'; 

$hrefPattern = '(?is)href=\"[^>]*(.*?)\"';

#get item by item id i.e {BB87FEE6-E4CF-4D86-986B-2D1B297A081F}
$item = Get-Item -Path "master:" -ID "{BB87FEE6-E4CF-4D86-986B-2D1B297A081F}"

#get field value by field name i.e Content
$htmlContent = $item.Fields["Content"].Value;

$anchorTagPatternMatches = [regex]::Matches($htmlContent,  
$anchorTagPattern);

if(![string]::IsNullOrEmpty($anchorTagPatternMatches)) {
    
    $anchorTagPatternMatches | ForEach-Object {
        $anchorText = $_.Groups[1].Value;
        $anchorTag = $_[0].Value;
        write-host $anchorTag
        write-host $anchorText
    if(![string]::IsNullOrEmpty($anchorTag)){   
        $hrefPatternMatches = [regex]::Matches($anchorTag, $hrefPattern);
        $href = $hrefPatternMatches[0].Value;
        $href = $href.Replace('href=','');
        write-host $href
        }
    }
    
}
Source Link

You can achieve it using RegEx as well -

$anchorTagPattern = '(?is)<a[^>]*>(.*?)<\/a>';
$hrefPattern = '(?is)href=\"[^>]*(.*?)\"';
#You can get Html content from item field
#$htmlContent = $item.Fields["Your Rich Text Content Field"].Value;
$htmlContent = @"
<div class="test">
   <div class="test">
    <blockquote>hello<br />
        <span class="test">hello</span>
    </blockquote>
    <a href="test.com">test</a>
  </div>
</div>
"@;
$anchorTagPatternMatches = [regex]::Matches($htmlContent, $anchorTagPattern);

if(![string]::IsNullOrEmpty($anchorTagPatternMatches)) {
    write-host $anchorTagPatternMatches
    $anchorText = $anchorTagPatternMatches[0].Groups[1].Value;
    $anchorTag = $anchorTagPatternMatches[0].Value;
    write-host $anchorText
    if(![string]::IsNullOrEmpty($anchorTag)){   
        $hrefPatternMatches = [regex]::Matches($anchorTag, $hrefPattern);
        $href = $hrefPatternMatches[0].Value;
        $href = $href.Replace('href=','');
        write-host $href
        }
}