[CmdletBinding()] param( [string]$Url = 'https://example.com/', [switch]$Json ) $ErrorActionPreference = 'Stop' try { $page = Invoke-WebRequest -Uri $Url -UseBasicParsing } catch { Write-Error ("Page failed: {0}" -f $_.Exception.Message) exit 1 } $links = [regex]::Matches($page.Content, ']*>', 'IgnoreCase') $iconLinks = @($links | Where-Object { $_.Value -match 'rel\s*=\s*["''][^"'']*icon' }) $urls = @() foreach ($link in $iconLinks) { $hrefMatch = [regex]::Match($link.Value, 'href\s*=\s*["'']([^"'']+)["'']', 'IgnoreCase') if ($hrefMatch.Success) { $urls += [Uri]::new([Uri]$Url, $hrefMatch.Groups[1].Value).AbsoluteUri } } if ($urls.Count -eq 0) { $urls += [Uri]::new([Uri]$Url, '/favicon.ico').AbsoluteUri } $results = @() $broken = 0 foreach ($iconUrl in ($urls | Select-Object -Unique)) { $status = $null $contentType = '' $length = 0 try { $iconResponse = Invoke-WebRequest -Uri $iconUrl -UseBasicParsing $status = [int]$iconResponse.StatusCode $contentType = [string]$iconResponse.Headers['Content-Type'] $length = $iconResponse.RawContentLength } catch { $status = $null } if ($null -eq $status -or $status -ge 400 -or $length -le 0) { $broken++ } $results += [pscustomobject]@{ url = $iconUrl status = $status contentType = $contentType bytes = $length } } if ($Json) { $results | ConvertTo-Json -Depth 3 } else { foreach ($item in $results) { Write-Host ("{0} {1} {2} {3} bytes" -f $item.status, $item.contentType, $item.url, $item.bytes) } Write-Host ("Иконок проверено: {0}, проблем: {1}" -f $results.Count, $broken) } if ($broken -gt 0) { exit 1 }