[CmdletBinding()] param( [Parameter(Mandatory = $true)] [string]$Path, [switch]$Recurse, [string]$Csv ) $ErrorActionPreference = 'Stop' Add-Type -AssemblyName System.Drawing function Get-ExifText { param( [System.Drawing.Image]$Image, [int]$Tag ) try { $item = $Image.GetPropertyItem($Tag) $text = [System.Text.Encoding]::ASCII.GetString($item.Value) return $text.Replace([char]0, ' ').Trim() } catch { return '' } } $resolved = (Resolve-Path -LiteralPath $Path -ErrorAction Stop).Path if (Test-Path -LiteralPath $resolved -PathType Leaf) { $files = @(Get-Item -LiteralPath $resolved) } elseif (Test-Path -LiteralPath $resolved -PathType Container) { $files = @(Get-ChildItem -LiteralPath $resolved -File -Recurse:$Recurse -ErrorAction SilentlyContinue) } else { throw "Путь не найден: $resolved" } $allowed = @('.jpg', '.jpeg', '.png', '.bmp', '.tif', '.tiff', '.gif') $rows = @() foreach ($file in $files) { $extension = $file.Extension.ToLowerInvariant() if ($extension -notin $allowed) { continue } $image = [System.Drawing.Image]::FromFile($file.FullName) try { $rows += [PSCustomObject]@{ File = $file.FullName Format = $extension.TrimStart('.').ToUpperInvariant() Width = $image.Width Height = $image.Height DpiX = [Math]::Round($image.HorizontalResolution, 1) DpiY = [Math]::Round($image.VerticalResolution, 1) SizeMB = [Math]::Round($file.Length / 1MB, 2) Modified = $file.LastWriteTime.ToString('yyyy-MM-dd HH:mm') Taken = Get-ExifText -Image $image -Tag 36867 Camera = ((Get-ExifText -Image $image -Tag 271) + ' ' + (Get-ExifText -Image $image -Tag 272)).Trim() } } finally { $image.Dispose() } } if ($rows.Count -eq 0) { Write-Host 'Изображения не найдены.' exit 0 } $rows | Format-Table -AutoSize -Property Format, Width, Height, DpiX, SizeMB, Modified, Taken, Camera, File if ($Csv) { $target = [System.IO.Path]::GetFullPath($Csv) $parent = Split-Path -Parent $target if ($parent -and -not (Test-Path -LiteralPath $parent)) { New-Item -ItemType Directory -Path $parent -Force | Out-Null } $rows | Export-Csv -LiteralPath $target -NoTypeInformation -Encoding UTF8 Write-Host "Отчет сохранен: $target" }