{"id":460810,"date":"2025-05-24T03:00:03","date_gmt":"2025-05-24T03:00:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=460810"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=460810","title":{"rendered":"<span>\u0414\u043e\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u0438\u0441\u043a\u0430 \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0441\u0441\u044b\u043b\u043e\u043a \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e PowerShell<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u043e\u0441\u043b\u0435 \u043f\u0440\u043e\u0447\u0442\u0435\u043d\u043d\u044b\u0445 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432, \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f <a class=\"mention\" href=\"\/users\/dmitryo\">@DmitryO<\/a> \u0440\u0435\u0448\u0438\u043b \u0447\u0442\u043e \u043d\u0430\u0434\u043e \u043f\u043e\u0434\u0443\u043c\u0430\u0442\u044c \u043e \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430<\/p>\n<h4>\u0424\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f:<\/h4>\n<ul>\n<li>\n<p>\u2705 <strong>\u0420\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u044b\u0435 \u043c\u0435\u0441\u0442\u0430 \u043f\u043e\u0438\u0441\u043a\u0430<\/strong>: \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u044b, \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u044b, \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<\/li>\n<li>\n<p>\u2705 \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 <strong>\u0414\u0435\u0442\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430<\/strong> \u0441 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u043e\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u043f\u043e \u0444\u0430\u0439\u043b\u0430\u043c<\/p>\n<\/li>\n<\/ul>\n<h4>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f:<\/h4>\n<ul>\n<li>\n<p>\ud83d\udd04 <strong>\u041c\u043e\u0434\u0443\u043b\u044c\u043d\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430<\/strong> \u0432\u043c\u0435\u0441\u0442\u043e \u043c\u043e\u043d\u043e\u043b\u0438\u0442\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430<\/p>\n<\/li>\n<li>\n<p>\ud83d\udd04 <strong>\u0420\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043b\u043e\u0433\u0438\u043a\u0438<\/strong> \u043f\u043e\u0438\u0441\u043a\u0430 \u0434\u043b\u044f XLSX \u0438 XLS \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>\ud83d\udd04 <strong>\u0423\u043b\u0443\u0447\u0448\u0435\u043d\u043d\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a<\/strong> \u0441 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u044b\u043c \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c<\/p>\n<\/li>\n<li>\n<p>\ud83d\udd04 <strong>\u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/strong> \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u0447\u0430\u043b\u043e\u043c \u043f\u043e\u0438\u0441\u043a\u0430<\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<h3>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430<\/h3>\n<h4>1. \u041c\u043e\u0434\u0443\u043b\u044c\u043d\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0439<\/h4>\n<p><strong>\u0411\u044b\u043b\u043e (\u043c\u043e\u043d\u043e\u043b\u0438\u0442\u043d\u044b\u0439 \u043a\u043e\u0434):<\/strong><\/p>\n<p>\u0412\u0435\u0441\u044c \u043a\u043e\u0434 \u0432 \u043e\u0434\u043d\u043e\u043c \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u0431\u043b\u043e\u043a\u0435 \u0441 \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043b\u043e\u0433\u0438\u043a\u0438<\/p>\n<pre><code> foreach ($currentFile in $files) {       # \u041f\u0440\u044f\u043c\u043e\u0439 \u0430\u043d\u0430\u043b\u0438\u0437 \u0444\u0430\u0439\u043b\u0430 \u0437\u0434\u0435\u0441\u044c \u0436\u0435       $archive = [System.IO.Compression.ZipFile]::OpenRead($currentFile)       # ... \u043b\u043e\u0433\u0438\u043a\u0430 \u043f\u043e\u0438\u0441\u043a\u0430 ...   }  <\/code><\/pre>\n<p><strong>\u0421\u0442\u0430\u043b\u043e (\u043c\u043e\u0434\u0443\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438):<\/strong><\/p>\n<p>\u0420\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/p>\n<pre><code>function Search-InXlsxFiles { ... }   function Process-XlsxFiles { ... }   function Analyze-XlsxFile { ... }   function Find-InExternalLinks { ... }  <\/code><\/pre>\n<h4>2. \u041f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 XLS\/XLSB \u0444\u0430\u0439\u043b\u043e\u0432<\/h4>\n<p><strong>\u0411\u044b\u043b\u043e:<\/strong><\/p>\n<pre><code>$files = Get-ChildItem -Path $searchPath -Filter \"*.xlsx\" -Recurse   $files += Get-ChildItem -Path $searchPath -Filter \"*.xlsm\" -Recurse  <\/code><\/pre>\n<p><strong>\u0421\u0442\u0430\u043b\u043e:<\/strong><\/p>\n<p>\u041e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u0432<\/p>\n<pre><code>function Search-InXlsFiles {       # \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 Excel COM API \u0434\u043b\u044f \u0441\u0442\u0430\u0440\u044b\u0445 \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u0432       $excel = New-Object -ComObject Excel.Application       $wb = $Excel.Workbooks.Open($FilePath, $false, $true)       $linkSources = $Workbook.LinkSources(1)   }      function Get-ExcelFiles {       param([string[]]$Extensions)       foreach ($ext in $Extensions) {           $files += Get-ChildItem -Path $SearchPath -Filter \"*.$ext\" -Recurse       }   }  <\/code><\/pre>\n<h4>3. \u0420\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u044b\u0435 \u043c\u0435\u0441\u0442\u0430 \u043f\u043e\u0438\u0441\u043a\u0430<\/h4>\n<p><strong>\u0411\u044b\u043b\u043e (\u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u0441\u0432\u044f\u0437\u0438):<\/strong><\/p>\n<pre><code>$linkFiles = $archive.Entries | Where-Object { $_.FullName -like 'xl\/externalLinks\/_rels\/*.rels' }   foreach ($linkFile in $linkFiles) {       # \u041f\u043e\u0438\u0441\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0441\u0432\u044f\u0437\u044f\u0445   }  <\/code><\/pre>\n<p><strong>\u0421\u0442\u0430\u043b\u043e (\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438):<\/strong><\/p>\n<pre><code>powershellCopy Code# 1. \u0417\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u0441\u0432\u044f\u0437\u0438   $externalLinks = Find-InExternalLinks $archive $FilePath $SearchFile      # 2. \u0418\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u044b     $namedRangeLinks = Find-InNamedRanges $archive $FilePath $SearchFile      # 3. \u0414\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u044b   $chartLinks = Find-InCharts $archive $FilePath $SearchFile      # 4. \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445   $dataValidationLinks = Find-InDataValidation $archive $FilePath $SearchFile   <\/code><\/pre>\n<h4>4. \u0423\u043b\u0443\u0447\u0448\u0435\u043d\u043d\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a<\/h4>\n<p><strong>\u0411\u044b\u043b\u043e:<\/strong><\/p>\n<pre><code>Codetry {       # \u041f\u0440\u043e\u0441\u0442\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430   } catch {       Write-Host \"\u041e\u0448\u0438\u0431\u043a\u0430: $($_.Exception.Message)\" -ForegroundColor Red   }  <\/code><\/pre>\n<p><strong>\u0421\u0442\u0430\u043b\u043e:<\/strong><\/p>\n<pre><code>Codefunction Test-FileAccessible {       try {           $stream = [System.IO.File]::Open($FilePath, 'Open', 'Read', 'None')           $stream.Close()           return $true       } catch {           return $false       }   }      # \u0412 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043a\u043e\u0434\u0435:   if (-not (Test-FileAccessible $FilePath)) {       Write-LogMessage \"    \u0424\u0430\u0439\u043b \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\" ([System.Drawing.Color]::Red)       return $foundLinks   }  <\/code><\/pre>\n<h4><\/h4>\n<h4>5. \u0414\u0435\u0442\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432<\/h4>\n<p><strong>\u0411\u044b\u043b\u043e:<\/strong><\/p>\n<pre><code>powershellCopy CodeWrite-Host \"\u041d\u0430\u0439\u0434\u0435\u043d\u043e \u0441\u0441\u044b\u043b\u043e\u043a: $foundLinks\"  <\/code><\/pre>\n<p><strong>\u0421\u0442\u0430\u043b\u043e:<\/strong><\/p>\n<pre><code>powershellCopy Codefunction Write-SearchResults {       Write-LogMessage \"\u0418\u0422\u041e\u0413\u041e\u0412\u0410\u042f \u0421\u0422\u0410\u0422\u0418\u0421\u0422\u0418\u041a\u0410:\" ([System.Drawing.Color]::Blue)       Write-LogMessage \"\u041f\u0440\u043e\u0432\u0435\u0440\u0435\u043d\u043e \u0444\u0430\u0439\u043b\u043e\u0432: $($Results.ProcessedFiles)\"       Write-LogMessage \"\u041d\u0430\u0439\u0434\u0435\u043d\u043e \u0441\u0441\u044b\u043b\u043e\u043a: $($Results.FoundLinks)\"              # \u0413\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u0430 \u043f\u043e \u0444\u0430\u0439\u043b\u0430\u043c \u0441 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439       $groupedLinks = $Results.FoundLinksInfo | Group-Object SourceFile       foreach ($group in $groupedLinks) {           Write-LogMessage \"\u0424\u0430\u0439\u043b: $($group.Name)\" ([System.Drawing.Color]::Green)           foreach ($link in $group.Group) {               Write-LogMessage \"  \u0422\u0438\u043f: $($link.LinkType)\"               Write-LogMessage \"  \u041c\u0435\u0441\u0442\u043e\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435: $($link.Location)\"           }       }   }  <\/code><\/pre>\n<h4>6. \u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/h4>\n<p><strong>\u041d\u0435 \u0411\u044b\u043b\u043e<\/strong><\/p>\n<p><strong>\u0421\u0442\u0430\u043b\u043e:<\/strong><\/p>\n<pre><code>Codefunction Test-SearchInputs {       if ([string]::IsNullOrWhiteSpace($SearchFile)) {           Write-LogMessage \"\u041e\u0428\u0418\u0411\u041a\u0410: \u041d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d \u0444\u0430\u0439\u043b \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430\" ([System.Drawing.Color]::Red)           return $false       }              if (-not (Test-Path $SearchPath)) {           Write-LogMessage \"\u041e\u0428\u0418\u0411\u041a\u0410: \u041f\u0430\u043f\u043a\u0430 \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430: $SearchPath\" ([System.Drawing.Color]::Red)           return $false       }              return $true   }<\/code><\/pre>\n<hr\/>\n<h3>P.S.<\/h3>\n<p>\u041f\u0440\u0430\u0432\u0434\u0430 \u0440\u0430\u043d\u0435\u0435 \u0432\u00a0\u0441\u0442\u0430\u0440\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0444\u0430\u0439\u043b\u043e\u0432 \u0437\u0430\u043d\u0438\u043c\u0430\u043b\u0430 \u0441\u0435\u043a\u0443\u043d\u0434 10\u00a0\u043f\u0440\u0438\u00a0\u0443\u0441\u043b\u043e\u0432\u0438\u0438 60\u00a0\u0444\u0430\u0439\u043b\u043e\u0432 \u0432\u00a0\u043f\u0430\u043f\u043a\u0435. \u0410\u00a0\u0442\u0435\u043f\u0435\u0440\u044c \u042d\u0442\u0438\u00a0\u0436\u0435 60\u00a0\u0444\u0430\u0439\u043b\u043e\u0432 \u043c\u043e\u0433\u0443 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0447\u0430\u0441\u0430\u043c\u0438 \u0438\u0437\u2011\u0437\u0430 \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u043e\u00a0\u0438\u043c\u0435\u043d\u0430\u043c, \u0438\u0431\u043e \u0435\u0441\u0442\u044c \u0444\u0430\u0439\u043b\u044b \u0441\u00a0\u043a\u0443\u0447\u0435\u0439 \u0438\u043c\u0435\u043d (60\u00a0\u0442\u044b\u0441 \u0432\u00a0\u043a\u0430\u0436\u0434\u043e\u043c). \u0410\u00a0\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u00a0\u0431\u044b\u043b\u043e \u0441\u0443\u043c\u0435\u0442\u044c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432\u00a0\u0447\u0443\u0436\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 \u0444\u0430\u0439\u043b\u043e\u0432 \u0438 \u043f\u043e\u043d\u044f\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438\u00a0\u0431\u044b\u0441\u0442\u0440\u043e&#8230; \u0410\u00a0\u0432\u00a0\u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0440\u0430\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u0442\u044f\u0433\u0438\u0432\u0430\u0442\u044c\u0441\u044f&#8230;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/912318\/\"> https:\/\/habr.com\/ru\/articles\/912318\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u043e\u0441\u043b\u0435 \u043f\u0440\u043e\u0447\u0442\u0435\u043d\u043d\u044b\u0445 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432, \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f <a class=\"mention\" href=\"\/users\/dmitryo\">@DmitryO<\/a> \u0440\u0435\u0448\u0438\u043b \u0447\u0442\u043e \u043d\u0430\u0434\u043e \u043f\u043e\u0434\u0443\u043c\u0430\u0442\u044c \u043e \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430<\/p>\n<h4>\u0424\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f:<\/h4>\n<ul>\n<li>\n<p>\u2705 <strong>\u0420\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u044b\u0435 \u043c\u0435\u0441\u0442\u0430 \u043f\u043e\u0438\u0441\u043a\u0430<\/strong>: \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u044b, \u0434\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u044b, \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/p>\n<\/li>\n<li>\n<p>\u2705 \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 <strong>\u0414\u0435\u0442\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430<\/strong> \u0441 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u043e\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u043f\u043e \u0444\u0430\u0439\u043b\u0430\u043c<\/p>\n<\/li>\n<\/ul>\n<h4>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u044b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f:<\/h4>\n<ul>\n<li>\n<p>\ud83d\udd04 <strong>\u041c\u043e\u0434\u0443\u043b\u044c\u043d\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430<\/strong> \u0432\u043c\u0435\u0441\u0442\u043e \u043c\u043e\u043d\u043e\u043b\u0438\u0442\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430<\/p>\n<\/li>\n<li>\n<p>\ud83d\udd04 <strong>\u0420\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043b\u043e\u0433\u0438\u043a\u0438<\/strong> \u043f\u043e\u0438\u0441\u043a\u0430 \u0434\u043b\u044f XLSX \u0438 XLS \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>\ud83d\udd04 <strong>\u0423\u043b\u0443\u0447\u0448\u0435\u043d\u043d\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a<\/strong> \u0441 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u044b\u043c \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c<\/p>\n<\/li>\n<li>\n<p>\ud83d\udd04 <strong>\u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/strong> \u043f\u0435\u0440\u0435\u0434 \u043d\u0430\u0447\u0430\u043b\u043e\u043c \u043f\u043e\u0438\u0441\u043a\u0430<\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<h3>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430<\/h3>\n<h4>1. \u041c\u043e\u0434\u0443\u043b\u044c\u043d\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0439<\/h4>\n<p><strong>\u0411\u044b\u043b\u043e (\u043c\u043e\u043d\u043e\u043b\u0438\u0442\u043d\u044b\u0439 \u043a\u043e\u0434):<\/strong><\/p>\n<p>\u0412\u0435\u0441\u044c \u043a\u043e\u0434 \u0432 \u043e\u0434\u043d\u043e\u043c \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u0431\u043b\u043e\u043a\u0435 \u0441 \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043b\u043e\u0433\u0438\u043a\u0438<\/p>\n<pre><code> foreach ($currentFile in $files) {       # \u041f\u0440\u044f\u043c\u043e\u0439 \u0430\u043d\u0430\u043b\u0438\u0437 \u0444\u0430\u0439\u043b\u0430 \u0437\u0434\u0435\u0441\u044c \u0436\u0435       $archive = [System.IO.Compression.ZipFile]::OpenRead($currentFile)       # ... \u043b\u043e\u0433\u0438\u043a\u0430 \u043f\u043e\u0438\u0441\u043a\u0430 ...   }  <\/code><\/pre>\n<p><strong>\u0421\u0442\u0430\u043b\u043e (\u043c\u043e\u0434\u0443\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438):<\/strong><\/p>\n<p>\u0420\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/p>\n<pre><code>function Search-InXlsxFiles { ... }   function Process-XlsxFiles { ... }   function Analyze-XlsxFile { ... }   function Find-InExternalLinks { ... }  <\/code><\/pre>\n<h4>2. \u041f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 XLS\/XLSB \u0444\u0430\u0439\u043b\u043e\u0432<\/h4>\n<p><strong>\u0411\u044b\u043b\u043e:<\/strong><\/p>\n<pre><code>$files = Get-ChildItem -Path $searchPath -Filter \"*.xlsx\" -Recurse   $files += Get-ChildItem -Path $searchPath -Filter \"*.xlsm\" -Recurse  <\/code><\/pre>\n<p><strong>\u0421\u0442\u0430\u043b\u043e:<\/strong><\/p>\n<p>\u041e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u0432<\/p>\n<pre><code>function Search-InXlsFiles {       # \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 Excel COM API \u0434\u043b\u044f \u0441\u0442\u0430\u0440\u044b\u0445 \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u0432       $excel = New-Object -ComObject Excel.Application       $wb = $Excel.Workbooks.Open($FilePath, $false, $true)       $linkSources = $Workbook.LinkSources(1)   }      function Get-ExcelFiles {       param([string[]]$Extensions)       foreach ($ext in $Extensions) {           $files += Get-ChildItem -Path $SearchPath -Filter \"*.$ext\" -Recurse       }   }  <\/code><\/pre>\n<h4>3. \u0420\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u044b\u0435 \u043c\u0435\u0441\u0442\u0430 \u043f\u043e\u0438\u0441\u043a\u0430<\/h4>\n<p><strong>\u0411\u044b\u043b\u043e (\u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u0441\u0432\u044f\u0437\u0438):<\/strong><\/p>\n<pre><code>$linkFiles = $archive.Entries | Where-Object { $_.FullName -like 'xl\/externalLinks\/_rels\/*.rels' }   foreach ($linkFile in $linkFiles) {       # \u041f\u043e\u0438\u0441\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0441\u0432\u044f\u0437\u044f\u0445   }  <\/code><\/pre>\n<p><strong>\u0421\u0442\u0430\u043b\u043e (\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438):<\/strong><\/p>\n<pre><code>powershellCopy Code# 1. \u0417\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u0441\u0432\u044f\u0437\u0438   $externalLinks = Find-InExternalLinks $archive $FilePath $SearchFile      # 2. \u0418\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u044b     $namedRangeLinks = Find-InNamedRanges $archive $FilePath $SearchFile      # 3. \u0414\u0438\u0430\u0433\u0440\u0430\u043c\u043c\u044b   $chartLinks = Find-InCharts $archive $FilePath $SearchFile      # 4. \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445   $dataValidationLinks = Find-InDataValidation $archive $FilePath $SearchFile   <\/code><\/pre>\n<h4>4. \u0423\u043b\u0443\u0447\u0448\u0435\u043d\u043d\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a<\/h4>\n<p><strong>\u0411\u044b\u043b\u043e:<\/strong><\/p>\n<pre><code>Codetry {       # \u041f\u0440\u043e\u0441\u0442\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430   } catch {       Write-Host \"\u041e\u0448\u0438\u0431\u043a\u0430: $($_.Exception.Message)\" -ForegroundColor Red   }  <\/code><\/pre>\n<p><strong>\u0421\u0442\u0430\u043b\u043e:<\/strong><\/p>\n<pre><code>Codefunction Test-FileAccessible {       try {           $stream = [System.IO.File]::Open($FilePath, 'Open', 'Read', 'None')           $stream.Close()           return $true       } catch {           return $false       }   }      # \u0412 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043a\u043e\u0434\u0435:   if (-not (Test-FileAccessible $FilePath)) {       Write-LogMessage \"    \u0424\u0430\u0439\u043b \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\" ([System.Drawing.Color]::Red)       return $foundLinks   }  <\/code><\/pre>\n<h4><\/h4>\n<h4>5. \u0414\u0435\u0442\u0430\u043b\u044c\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432<\/h4>\n<p><strong>\u0411\u044b\u043b\u043e:<\/strong><\/p>\n<pre><code>powershellCopy CodeWrite-Host \"\u041d\u0430\u0439\u0434\u0435\u043d\u043e \u0441\u0441\u044b\u043b\u043e\u043a: $foundLinks\"  <\/code><\/pre>\n<p><strong>\u0421\u0442\u0430\u043b\u043e:<\/strong><\/p>\n<pre><code>powershellCopy Codefunction Write-SearchResults {       Write-LogMessage \"\u0418\u0422\u041e\u0413\u041e\u0412\u0410\u042f \u0421\u0422\u0410\u0422\u0418\u0421\u0422\u0418\u041a\u0410:\" ([System.Drawing.Color]::Blue)       Write-LogMessage \"\u041f\u0440\u043e\u0432\u0435\u0440\u0435\u043d\u043e \u0444\u0430\u0439\u043b\u043e\u0432: $($Results.ProcessedFiles)\"       Write-LogMessage \"\u041d\u0430\u0439\u0434\u0435\u043d\u043e \u0441\u0441\u044b\u043b\u043e\u043a: $($Results.FoundLinks)\"              # \u0413\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u0430 \u043f\u043e \u0444\u0430\u0439\u043b\u0430\u043c \u0441 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439       $groupedLinks = $Results.FoundLinksInfo | Group-Object SourceFile       foreach ($group in $groupedLinks) {           Write-LogMessage \"\u0424\u0430\u0439\u043b: $($group.Name)\" ([System.Drawing.Color]::Green)           foreach ($link in $group.Group) {               Write-LogMessage \"  \u0422\u0438\u043f: $($link.LinkType)\"               Write-LogMessage \"  \u041c\u0435\u0441\u0442\u043e\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435: $($link.Location)\"           }       }   }  <\/code><\/pre>\n<h4>6. \u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/h4>\n<p><strong>\u041d\u0435 \u0411\u044b\u043b\u043e<\/strong><\/p>\n<p><strong>\u0421\u0442\u0430\u043b\u043e:<\/strong><\/p>\n<pre><code>Codefunction Test-SearchInputs {       if ([string]::IsNullOrWhiteSpace($SearchFile)) {           Write-LogMessage \"\u041e\u0428\u0418\u0411\u041a\u0410: \u041d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d \u0444\u0430\u0439\u043b \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430\" ([System.Drawing.Color]::Red)           return $false       }              if (-not (Test-Path $SearchPath)) {           Write-LogMessage \"\u041e\u0428\u0418\u0411\u041a\u0410: \u041f\u0430\u043f\u043a\u0430 \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430: $SearchPath\" ([System.Drawing.Color]::Red)           return $false       }              return $true   }<\/code><\/pre>\n<hr\/>\n<h3>P.S.<\/h3>\n<p>\u041f\u0440\u0430\u0432\u0434\u0430 \u0440\u0430\u043d\u0435\u0435 \u0432\u00a0\u0441\u0442\u0430\u0440\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0444\u0430\u0439\u043b\u043e\u0432 \u0437\u0430\u043d\u0438\u043c\u0430\u043b\u0430 \u0441\u0435\u043a\u0443\u043d\u0434 10\u00a0\u043f\u0440\u0438\u00a0\u0443\u0441\u043b\u043e\u0432\u0438\u0438 60\u00a0\u0444\u0430\u0439\u043b\u043e\u0432 \u0432\u00a0\u043f\u0430\u043f\u043a\u0435. \u0410\u00a0\u0442\u0435\u043f\u0435\u0440\u044c \u042d\u0442\u0438\u00a0\u0436\u0435 60\u00a0\u0444\u0430\u0439\u043b\u043e\u0432 \u043c\u043e\u0433\u0443 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0447\u0430\u0441\u0430\u043c\u0438 \u0438\u0437\u2011\u0437\u0430 \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u043e\u00a0\u0438\u043c\u0435\u043d\u0430\u043c, \u0438\u0431\u043e \u0435\u0441\u0442\u044c \u0444\u0430\u0439\u043b\u044b \u0441\u00a0\u043a\u0443\u0447\u0435\u0439 \u0438\u043c\u0435\u043d (60\u00a0\u0442\u044b\u0441 \u0432\u00a0\u043a\u0430\u0436\u0434\u043e\u043c). \u0410\u00a0\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u00a0\u0431\u044b\u043b\u043e \u0441\u0443\u043c\u0435\u0442\u044c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432\u00a0\u0447\u0443\u0436\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 \u0444\u0430\u0439\u043b\u043e\u0432 \u0438 \u043f\u043e\u043d\u044f\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438\u00a0\u0431\u044b\u0441\u0442\u0440\u043e&#8230; \u0410\u00a0\u0432\u00a0\u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0440\u0430\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u0442\u044f\u0433\u0438\u0432\u0430\u0442\u044c\u0441\u044f&#8230;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/912318\/\"> https:\/\/habr.com\/ru\/articles\/912318\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-460810","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/460810","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=460810"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/460810\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=460810"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=460810"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=460810"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}