[CmdletBinding()] param( [Parameter(Mandatory = $true)] [string]$Path, [string]$OutDir = (Join-Path (Get-Location) 'pptx_images'), [switch]$Force ) $ErrorActionPreference = 'Stop' $resolved = (Resolve-Path -LiteralPath $Path -ErrorAction Stop).Path $extension = [IO.Path]::GetExtension($resolved).ToLowerInvariant() if ($extension -notin @('.pptx', '.pptm', '.potx')) { throw 'Поддерживаются файлы .pptx, .pptm и .potx' } Add-Type -AssemblyName System.IO.Compression.FileSystem if (-not (Test-Path -LiteralPath $OutDir)) { New-Item -ItemType Directory -Path $OutDir -Force | Out-Null } $outRoot = (Resolve-Path -LiteralPath $OutDir).Path $archive = $null try { $archive = [System.IO.Compression.ZipFile]::OpenRead($resolved) $entries = $archive.Entries | Where-Object { $_.FullName -like 'ppt/media/*' -and $_.Name } $saved = 0 $skipped = 0 foreach ($entry in $entries) { $target = Join-Path $outRoot $entry.Name if ((Test-Path -LiteralPath $target) -and -not $Force) { Write-Host "Пропуск, уже существует: $target" $skipped++ continue } [System.IO.Compression.ZipFileExtensions]::ExtractToFile($entry, $target, $true) Write-Host "Готово: $target" $saved++ } Write-Host "Сохранено файлов: $saved, пропущено: $skipped" } finally { if ($archive) { $archive.Dispose() } }