[CmdletBinding()] param( [Parameter(Mandatory = $true)] [string]$Path, [string]$CsvPath ) $ErrorActionPreference = 'Stop' $resolved = (Resolve-Path -LiteralPath $Path -ErrorAction Stop).Path $extension = [IO.Path]::GetExtension($resolved).ToLowerInvariant() if ($extension -notin @('.pptx', '.pptm', '.ppt')) { throw 'Поддерживаются файлы .pptx, .pptm и .ppt' } $powerPoint = $null $presentation = $null try { try { $powerPoint = New-Object -ComObject PowerPoint.Application } catch { throw 'PowerPoint не найден. Установите настольный Microsoft PowerPoint.' } $presentation = $powerPoint.Presentations.Open($resolved, $true, $false, $false) $rows = foreach ($slide in $presentation.Slides) { $title = '' try { if ($slide.Shapes.Title) { $title = [string]$slide.Shapes.Title.TextFrame.TextRange.Text } } catch { $title = '' } $texts = New-Object System.Collections.Generic.List[string] foreach ($shape in $slide.Shapes) { try { if ($shape.HasTextFrame -eq -1 -and $shape.TextFrame.HasText -eq -1) { $value = [string]$shape.TextFrame.TextRange.Text if ($value) { $texts.Add($value) } } } catch { continue } } [pscustomobject]@{ Slide = $slide.SlideIndex Title = ($title -replace '\s+', ' ').Trim() Text = (($texts -join ' ') -replace '\s+', ' ').Trim() } } $rows | Format-Table -AutoSize if ($CsvPath) { $rows | Export-Csv -LiteralPath $CsvPath -NoTypeInformation -Encoding UTF8 Write-Host "Отчёт сохранён: $CsvPath" } } finally { if ($presentation) { $presentation.Close() } if ($powerPoint) { $powerPoint.Quit() } if ($presentation) { [void][Runtime.InteropServices.Marshal]::ReleaseComObject($presentation) } if ($powerPoint) { [void][Runtime.InteropServices.Marshal]::ReleaseComObject($powerPoint) } [GC]::Collect() }