How to find all of the Sitecore Items that use aliases?

Recently I had to find all the items being linked by aliases. Because we had hundreds of aliases and no one wanted to go one by one to check where are they linking to I decided to prepare a PowerShell script to generate a report. Here is the code of it:

$itemList = @()
$allPaths = @(
    "master:\system\Aliases"
    )
    
ForEach($path in $allPaths)
{
    $itemList += Get-ChildItem $path -Recurse | Where-Object {
        $_.TemplateID -eq "{54BCFFB7-8F46-4948-AE74-DA5B6B5AFA86}"
    }
}

$reportProps = @{
    Title = "Aliases Report"
    InfoTitle = "This is a report showing items being linked by aliases"
    InfoDescription = "Total entries found: $($itemList.length)"
    PageSize = 25
}

$report = New-Object System.Collections.Generic.List[PSObject]

ForEach ($item in $itemList)
{    
    $linkedItem = $item.PSFields."Linked item"
    $found = $linkedItem.Value -match '.*id="(.*?)".*'
    $foundItemPath = ""
    $foundID = ""
    if ($found)
    {
        $foundID = $matches[1]
        
        if ($foundItem = Get-Item -Path "master:" -ID $foundID -ErrorAction SilentlyContinue)
        {
            $foundItemPath = $foundItem.FullPath
        }
        else
        {
            $foundItemPath = "Broken Link"
        }
        
    }
    
    $newObject = New-Object PSObject @{__Icon = $item.__Icon; DisplayName = $item.DisplayName; FullPath = $item.FullPath; ID = $item.ID; URL = $linkedItem.Url; LinkedItemPath = $foundItemPath; LinkedItemID = $foundID}
    $report.Add($newObject)
}

$report | Show-ListView @reportProps -Property `
    @{ Label = "Alias Path"; Expression = { $_.FullPath} },
    @{ Label = "Alias Id"; Expression = { $_.ID } },
    @{ Label = "LinkedItem ID"; Expression = { $_.LinkedItemID } },
    @{ Label = "Linked Url"; Expression = { $_.URL } },
    @{ Label = "LinkedItem Path"; Expression = { $_.LinkedItemPath } }
Close-Window