Find all sites where a feature is activated

A PowerShell script to find where a Feature is activated in a site or webapplication.

$featureId = "22a9ef51-737b-4ff2-9346-694633fe4416"
$WebApp = Get-SPWebApplication https://webapp.contoso.com 

foreach ($s in $WebApp.Sites ) {
    Function FindFeature($obj, $fId)
    {
        $obj.Features | ? { $_.DefinitionId -eq $fId } | % { $_.Parent.Url }
	$obj.AllWebs | % {
            $_.Features | ? { $_.DefinitionId -eq $featureId } | % { $_.Parent.Url }
	    if ($_.AllWebs.Count -gt 0) {
	      FindFeature($_, $fId);
	    }
	  }
    }
    FindFeature $s $featureId
}