{"id":460097,"date":"2025-05-18T21:00:19","date_gmt":"2025-05-18T21:00:19","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=460097"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=460097","title":{"rendered":"<span>\u041a\u0430\u043a \u044f \u043f\u0440\u0438\u0440\u0443\u0447\u0430\u043b Excel: \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u044f \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\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b \u043f\u043e\u0438\u0441\u043a \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0441\u0441\u044b\u043b\u043e\u043a \u0432 Excel-\u0444\u0430\u0439\u043b\u0430\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e PowerShell, \u0438 \u043a\u0430\u043a\u0438\u0435 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043f\u0440\u0435\u043e\u0434\u043e\u043b\u0435\u0442\u044c \u043f\u043e \u043f\u0443\u0442\u0438. \u0418\u0441\u0442\u043e\u0440\u0438\u044f \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 COM-\u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438, \u0440\u0430\u0437\u0431\u043e\u0440 ZIP-\u0430\u0440\u0445\u0438\u0432\u043e\u0432, XML-\u043f\u0430\u0440\u0441\u0438\u043d\u0433, \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 GUI \u043d\u0430 Windows Forms.<\/p>\n<h4>\u041f\u0440\u0435\u0434\u044b\u0441\u0442\u043e\u0440\u0438\u044f \u0438 \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438<\/h4>\n<p>\u0412 \u043d\u0430\u0448\u0435\u0439 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 Excel \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0444\u0438\u043d\u0430\u043d\u0441\u043e\u0432\u043e\u0439 \u043e\u0442\u0447\u0451\u0442\u043d\u043e\u0441\u0442\u0438. \u0421\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043b\u0430\u0441\u044c \u0441\u043b\u043e\u0436\u043d\u0430\u044f \u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0432\u0437\u0430\u0438\u043c\u043e\u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432, \u0433\u0434\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0443 \u0434\u0435\u0441\u044f\u0442\u043a\u043e\u0432 \u0434\u0440\u0443\u0433\u0438\u0445. \u0417\u0430\u0434\u0430\u0447\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043b\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 \u0432\u0441\u0435 \u0444\u0430\u0439\u043b\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p><strong>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f:<\/strong><\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u0438\u0441\u043a \u043f\u043e \u0432\u0441\u0435\u043c \u0442\u0438\u043f\u0430\u043c Excel-\u0444\u0430\u0439\u043b\u043e\u0432 (XLSX, XLSM, XLS, XLSB)<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0439 \u043e\u0431\u0445\u043e\u0434 \u043f\u0430\u043f\u043e\u043a<\/p>\n<\/li>\n<li>\n<p>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a \u0438 \u043f\u043e\u0432\u0440\u0435\u0436\u0434\u0451\u043d\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043d\u044f\u0442\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/p>\n<\/li>\n<\/ul>\n<h4>\u0422\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043d\u0430\u043b\u0438\u0437 \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u0432 Excel<\/h4>\n<p>\u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c\u0441\u044f \u0441 \u0444\u043e\u0440\u043c\u0430\u0442\u0430\u043c\u0438 \u0444\u0430\u0439\u043b\u043e\u0432:<\/p>\n<ol>\n<li>\n<p><strong>XLSX\/XLSM<\/strong> &#8212; Office Open XML, \u043f\u043e \u0441\u0443\u0442\u0438 ZIP-\u0430\u0440\u0445\u0438\u0432 \u0441 XML-\u0444\u0430\u0439\u043b\u0430\u043c\u0438<\/p>\n<\/li>\n<li>\n<p><strong>XLS<\/strong> &#8212; \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 Legacy Excel<\/p>\n<\/li>\n<li>\n<p><strong>XLSB<\/strong> &#8212; \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u0441 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e<\/p>\n<\/li>\n<\/ol>\n<p>\u0414\u043b\u044f \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u0432 (XLSX\/XLSM) \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u043e\u0434\u0445\u043e\u0434:<\/p>\n<pre><code class=\"powershell\"># \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0441\u0441\u044b\u043b\u043e\u043a \u0438\u0437 XLSX\/XLSM   function Get-ExcelLinksFromModernFormat {       param (           [string]$FilePath       )              try {           # \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e           $tempPath = [System.IO.Path]::GetTempPath() + [System.Guid]::NewGuid().ToString()           New-Item -ItemType Directory -Path $tempPath | Out-Null                      # \u041a\u043e\u043f\u0438\u0440\u0443\u0435\u043c Excel-\u0444\u0430\u0439\u043b \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e ZIP           $zipPath = Join-Path $tempPath \"temp.zip\"           Copy-Item -Path $FilePath -Destination $zipPath                      # \u0420\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u044b\u0432\u0430\u0435\u043c           Expand-Archive -Path $zipPath -DestinationPath $tempPath                      # \u0418\u0449\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0438 \u0432 workbook.xml           $workbookXml = Join-Path $tempPath \"xl\\workbook.xml\"           if (Test-Path $workbookXml) {               [xml]$xml = Get-Content $workbookXml               $externalLinks = $xml.workbook.externalReferences.externalReference                              foreach ($link in $externalLinks) {                   # \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u0443\u0442\u044c \u043a \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u043c\u0443 \u0444\u0430\u0439\u043b\u0443 \u0438\u0437 rels                   $rId = $link.id                   $relsPath = Join-Path $tempPath \"xl\\_rels\\workbook.xml.rels\"                   [xml]$rels = Get-Content $relsPath                   $target = $rels.Relationships.Relationship |                        Where-Object { $_.Id -eq $rId } |                       Select-Object -ExpandProperty Target                                      [PSCustomObject]@{                       SourceFile = $FilePath                       LinkedFile = $target                       RelationType = \"External\"                   }               }           }       }       catch {           Write-Warning \"\u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0444\u0430\u0439\u043b\u0430 $FilePath : $_\"       }       finally {           # \u041e\u0447\u0438\u0441\u0442\u043a\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432           if (Test-Path $tempPath) {               Remove-Item -Path $tempPath -Recurse -Force           }       }   }   <\/code><\/pre>\n<p>\u0414\u043b\u044f \u0441\u0442\u0430\u0440\u044b\u0445 \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u0432 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c COM-\u043e\u0431\u044a\u0435\u043a\u0442 Excel:<\/p>\n<pre><code class=\"powershell\"># \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043e \u0441\u0442\u0430\u0440\u044b\u043c\u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u0430\u043c\u0438 \u0447\u0435\u0440\u0435\u0437 COM   function Get-ExcelLinksFromLegacyFormat {       param (           [string]$FilePath       )              $excel = $null       $workbook = $null              try {           $excel = New-Object -ComObject Excel.Application           $excel.Visible = $false           $excel.DisplayAlerts = $false                      # \u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0441 \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u043c\u0438 \u043c\u0430\u043a\u0440\u043e\u0441\u0430\u043c\u0438           $workbook = $excel.Workbooks.Open($FilePath, 0, $true)                      # \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0441\u0441\u044b\u043b\u043e\u043a           $links = @($workbook.LinkSources([Microsoft.Office.Interop.Excel.XlLink]::xlExcelLinks))                      foreach ($link in $links) {               [PSCustomObject]@{                   SourceFile = $FilePath                   LinkedFile = $link                   RelationType = \"External\"               }           }       }       catch {           Write-Warning \"\u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0444\u0430\u0439\u043b\u0430 $FilePath : $_\"       }       finally {           if ($workbook) {               $workbook.Close($false)           }           if ($excel) {               $excel.Quit()               [System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel) | Out-Null           }           [System.GC]::Collect()           [System.GC]::WaitForPendingFinalizers()       }   }   <\/code><\/pre>\n<h4>\u041c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430<\/h4>\n<p>\u0414\u043b\u044f \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u0443\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0444\u0430\u0439\u043b\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Jobs:<\/p>\n<pre><code class=\"powershell\">Codefunction Process-ExcelFilesInParallel {       param (           [string]$FolderPath,           [int]$MaxJobs = 3       )              $files = Get-ChildItem -Path $FolderPath -Recurse -Include \"*.xlsx\",\"*.xlsm\",\"*.xls\",\"*.xlsb\"       $jobs = @()       $results = @()              foreach ($file in $files) {           # \u0416\u0434\u0451\u043c, \u0435\u0441\u043b\u0438 \u0434\u043e\u0441\u0442\u0438\u0433\u043d\u0443\u0442 \u043b\u0438\u043c\u0438\u0442 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447           while ((Get-Job -State Running).Count -ge $MaxJobs) {               Start-Sleep -Milliseconds 500               Get-Job | Where-Object { $_.State -eq \"Completed\" } | ForEach-Object {                   $results += Receive-Job -Job $_                   Remove-Job -Job $_               }           }                      # \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043d\u043e\u0432\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443           $jobs += Start-Job -ScriptBlock {               param($file)               if ($file.Extension -in \".xlsx\",\".xlsm\") {                   Get-ExcelLinksFromModernFormat -FilePath $file.FullName               }               else {                   Get-ExcelLinksFromLegacyFormat -FilePath $file.FullName               }           } -ArgumentList $file       }              # \u041e\u0436\u0438\u0434\u0430\u0435\u043c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0437\u0430\u0434\u0430\u0447       Wait-Job -Job $jobs | Out-Null       $results += Get-Job | Receive-Job       Get-Job | Remove-Job              return $results   }  <\/code><\/pre>\n<h4>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 GUI \u043d\u0430 Windows Forms<\/h4>\n<p>\u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Windows Forms:<\/p>\n<pre><code class=\"powershell\">powershellCopy CodeAdd-Type -AssemblyName System.Windows.Forms   Add-Type -AssemblyName System.Drawing      function Create-ExcelLinksFinderGUI {       $form = New-Object System.Windows.Forms.Form       $form.Text = \"Excel Links Finder\"       $form.Size = New-Object System.Drawing.Size(800,600)       $form.StartPosition = \"CenterScreen\"          # \u041a\u043e\u043d\u0442\u0440\u043e\u043b\u044b \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u0430 \u0444\u0430\u0439\u043b\u0430-\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430       $sourceLabel = New-Object System.Windows.Forms.Label       $sourceLabel.Location = New-Object System.Drawing.Point(10,20)       $sourceLabel.Size = New-Object System.Drawing.Size(280,20)       $sourceLabel.Text = \"\u0412\u044b\u0431\u0435\u0440\u0438\u0442\u0435 \u0444\u0430\u0439\u043b \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0441\u0441\u044b\u043b\u043e\u043a:\"       $form.Controls.Add($sourceLabel)          $sourceTextBox = New-Object System.Windows.Forms.TextBox       $sourceTextBox.Location = New-Object System.Drawing.Point(10,40)       $sourceTextBox.Size = New-Object System.Drawing.Size(580,20)       $form.Controls.Add($sourceTextBox)          $sourceBrowseButton = New-Object System.Windows.Forms.Button       $sourceBrowseButton.Location = New-Object System.Drawing.Point(600,40)       $sourceBrowseButton.Size = New-Object System.Drawing.Size(75,20)       $sourceBrowseButton.Text = \"\u041e\u0431\u0437\u043e\u0440...\"       $sourceBrowseButton.Add_Click({           $fileDialog = New-Object System.Windows.Forms.OpenFileDialog           $fileDialog.Filter = \"Excel Files|*.xlsx;*.xlsm;*.xls;*.xlsb\"           if ($fileDialog.ShowDialog() -eq 'OK') {               $sourceTextBox.Text = $fileDialog.FileName           }       })       $form.Controls.Add($sourceBrowseButton)          # \u041f\u0440\u043e\u0433\u0440\u0435\u0441\u0441-\u0431\u0430\u0440       $progressBar = New-Object System.Windows.Forms.ProgressBar       $progressBar.Location = New-Object System.Drawing.Point(10,80)       $progressBar.Size = New-Object System.Drawing.Size(665,20)       $form.Controls.Add($progressBar)          # \u041b\u043e\u0433-\u0431\u043e\u043a\u0441       $logBox = New-Object System.Windows.Forms.RichTextBox       $logBox.Location = New-Object System.Drawing.Point(10,110)       $logBox.Size = New-Object System.Drawing.Size(665,400)       $logBox.ReadOnly = $true       $logBox.BackColor = [System.Drawing.Color]::White       $form.Controls.Add($logBox)          # \u041a\u043d\u043e\u043f\u043a\u0430 \u0437\u0430\u043f\u0443\u0441\u043a\u0430       $startButton = New-Object System.Windows.Forms.Button       $startButton.Location = New-Object System.Drawing.Point(10,520)       $startButton.Size = New-Object System.Drawing.Size(150,30)       $startButton.Text = \"\u041d\u0430\u0447\u0430\u0442\u044c \u043f\u043e\u0438\u0441\u043a\"       $startButton.Add_Click({           $logBox.Clear()           $progressBar.Value = 0                      if ([string]::IsNullOrEmpty($sourceTextBox.Text)) {               [System.Windows.Forms.MessageBox]::Show(\"\u0412\u044b\u0431\u0435\u0440\u0438\u0442\u0435 \u0444\u0430\u0439\u043b \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430!\")               return           }              $startButton.Enabled = $false           $sourceBrowseButton.Enabled = $false              # \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u043e\u0438\u0441\u043a \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435           $searchJob = [System.ComponentModel.BackgroundWorker]::new()           $searchJob.WorkerReportsProgress = $true           $searchJob.Add_DoWork({               param($sender, $e)               Search-ExcelLinks -SourceFile $sourceTextBox.Text -Progress $sender           })           $searchJob.Add_ProgressChanged({               param($sender, $e)               $progressBar.Value = $e.ProgressPercentage               $logBox.AppendText($e.UserState + \"`n\")               $logBox.ScrollToCaret()           })           $searchJob.Add_RunWorkerCompleted({               $startButton.Enabled = $true               $sourceBrowseButton.Enabled = $true               [System.Windows.Forms.MessageBox]::Show(\"\u041f\u043e\u0438\u0441\u043a \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d!\")           })           $searchJob.RunWorkerAsync()       })       $form.Controls.Add($startButton)          return $form   }   <\/code><\/pre>\n<h4>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a \u0438 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c<\/h4>\n<p>\u0412\u0430\u0436\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e \u0441\u0442\u0430\u043b\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"powershell\"># \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f   function Set-ExecutionPolicy {       try {           $currentPolicy = Get-ExecutionPolicy           if ($currentPolicy -eq \"Restricted\") {               # \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0441\u0430\u043c\u043e\u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442               $cert = New-SelfSignedCertificate `                   -Subject \"CN=ExcelLinksFinder\" `                   -Type CodeSigningCert `                   -CertStoreLocation \"Cert:\\CurrentUser\\My\"                  # \u041f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0441\u043a\u0440\u0438\u043f\u0442               $scriptPath = $MyInvocation.MyCommand.Path               Set-AuthenticodeSignature -FilePath $scriptPath -Certificate $cert                  # \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0443               Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force           }       }       catch {           Write-Error \"\u041e\u0448\u0438\u0431\u043a\u0430 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f: $_\"           return $false       }       return $true   }      # \u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a Excel   function Handle-ExcelError {       param (           [string]$FilePath,           [System.Exception]$Error       )              switch -Regex ($Error.Exception.Message) {           \".*is already open.*\" {               Write-Warning \"\u0424\u0430\u0439\u043b $FilePath \u0443\u0436\u0435 \u043e\u0442\u043a\u0440\u044b\u0442 \u0432 Excel\"               return $false           }           \".*cannot access.*\" {               Write-Warning \"\u041d\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0444\u0430\u0439\u043b\u0443 $FilePath\"               return $false           }           \".*is corrupt.*\" {               try {                   # \u041f\u0440\u043e\u0431\u0443\u0435\u043c \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0444\u0430\u0439\u043b                   $excel = New-Object -ComObject Excel.Application                   $excel.Visible = $false                   $excel.DisplayAlerts = $false                   $workbook = $excel.Workbooks.Open($FilePath, 6) # 6 = xlRepairFile                   return $true               }               catch {                   Write-Warning \"\u041d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0444\u0430\u0439\u043b $FilePath\"                   return $false               }               finally {                   if ($excel) {                       $excel.Quit()                       [System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel)                   }               }           }           default {               Write-Warning \"\u041d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 $FilePath : $Error\"               return $false           }       }   }   <\/code><\/pre>\n<h4>\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438<\/h4>\n<p>\u0414\u043b\u044f \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e \u043f\u0430\u043c\u044f\u0442\u0438:<\/p>\n<pre><code class=\"powershell\"># \u041a\u044d\u0448 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432   $script:LinkCache = @{}      function Get-CachedLinks {       param (           [string]$FilePath       )              $fileHash = (Get-FileHash -Path $FilePath).Hash              if ($script:LinkCache.ContainsKey($fileHash)) {           $cachedResult = $script:LinkCache[$fileHash]           $lastWrite = (Get-Item $FilePath).LastWriteTime                      # \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043a\u044d\u0448\u0430           if ($lastWrite -le $cachedResult.CacheTime) {               return $cachedResult.Links           }       }              return $null   }      function Set-CachedLinks {       param (           [string]$FilePath,           [array]$Links       )              $fileHash = (Get-FileHash -Path $FilePath).Hash       $script:LinkCache[$fileHash] = @{           CacheTime = Get-Date           Links = $Links       }   }      # \u041e\u0447\u0438\u0441\u0442\u043a\u0430 \u043f\u0430\u043c\u044f\u0442\u0438   function Clear-ExcelProcesses {       Get-Process excel -ErrorAction SilentlyContinue |        Where-Object { $_.MainWindowTitle -eq \"\" } |        Stop-Process -Force              [System.GC]::Collect()       [System.GC]::WaitForPendingFinalizers()   }   <\/code><\/pre>\n<h4>\u041b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u043e\u0442\u0447\u0451\u0442\u043d\u043e\u0441\u0442\u044c<\/h4>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0435 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0442\u0447\u0451\u0442\u043e\u0432:<\/p>\n<pre><code class=\"powershell\">odefunction Write-Log {       param(           [string]$Message,           [ValidateSet('Info','Warning','Error')]           [string]$Level = 'Info'       )              $logMessage = \"{0} [{1}] {2}\" -f (Get-Date -Format \"yyyy-MM-dd HH:mm:ss\"), $Level, $Message              switch ($Level) {           'Info'    { Write-Host $logMessage -ForegroundColor Green }           'Warning' { Write-Host $logMessage -ForegroundColor Yellow }           'Error'   { Write-Host $logMessage -ForegroundColor Red }       }              # \u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0432 \u0444\u0430\u0439\u043b       $logMessage | Out-File -FilePath \"ExcelLinksFinder.log\" -Append   }      function Export-Results {       param(           [array]$Results,           [string]$OutputPath       )              $excel = New-Object -ComObject Excel.Application       $excel.Visible = $false              $workbook = $excel.Workbooks.Add()       $worksheet = $workbook.Worksheets.Item(1)              # \u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438       $worksheet.Cells.Item(1,1) = \"\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0444\u0430\u0439\u043b\"       $worksheet.Cells.Item(1,2) = \"\u0421\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b\"       $worksheet.Cells.Item(1,3) = \"\u0422\u0438\u043f \u0441\u0432\u044f\u0437\u0438\"       $worksheet.Cells.Item(1,4) = \"\u0414\u0430\u0442\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438\"              # \u0414\u0430\u043d\u043d\u044b\u0435       $row = 2       foreach ($result in $Results) {           $worksheet.Cells.Item($row,1) = $result.SourceFile           $worksheet.Cells.Item($row,2) = $result.LinkedFile           $worksheet.Cells.Item($row,3) = $result.RelationType           $worksheet.Cells.Item($row,4) = Get-Date -Format \"yyyy-MM-dd HH:mm:ss\"           $row++       }              # \u0424\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435       $range = $worksheet.Range(\"A1:D1\")       $range.Font.Bold = $true       $worksheet.Columns.AutoFit()              # \u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435       $workbook.SaveAs($OutputPath)       $workbook.Close($true)       $excel.Quit()              [System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel)   }   <\/code><\/pre>\n<h4>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h4>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u043d\u0430\u0434\u0451\u0436\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0441\u0441\u044b\u043b\u043e\u043a \u0432 Excel-\u0444\u0430\u0439\u043b\u0430\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0439:<\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0432\u0441\u0435 \u0444\u043e\u0440\u043c\u0430\u0442\u044b Excel-\u0444\u0430\u0439\u043b\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>\u0418\u043c\u0435\u0435\u0442 \u0443\u0434\u043e\u0431\u043d\u044b\u0439 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441<\/p>\n<\/li>\n<li>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0438<\/p>\n<\/li>\n<li>\n<p>\u0412\u0435\u0434\u0451\u0442 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0435 \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/p>\n<\/li>\n<li>\n<p>\u0424\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0435 \u043e\u0442\u0447\u0451\u0442\u044b<\/p>\n<\/li>\n<\/ul>\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\/910454\/\"> https:\/\/habr.com\/ru\/articles\/910454\/<\/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\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440! \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b \u043f\u043e\u0438\u0441\u043a \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0441\u0441\u044b\u043b\u043e\u043a \u0432 Excel-\u0444\u0430\u0439\u043b\u0430\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e PowerShell, \u0438 \u043a\u0430\u043a\u0438\u0435 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043f\u0440\u0435\u043e\u0434\u043e\u043b\u0435\u0442\u044c \u043f\u043e \u043f\u0443\u0442\u0438. \u0418\u0441\u0442\u043e\u0440\u0438\u044f \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 COM-\u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438, \u0440\u0430\u0437\u0431\u043e\u0440 ZIP-\u0430\u0440\u0445\u0438\u0432\u043e\u0432, XML-\u043f\u0430\u0440\u0441\u0438\u043d\u0433, \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 GUI \u043d\u0430 Windows Forms.<\/p>\n<h4>\u041f\u0440\u0435\u0434\u044b\u0441\u0442\u043e\u0440\u0438\u044f \u0438 \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438<\/h4>\n<p>\u0412 \u043d\u0430\u0448\u0435\u0439 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 Excel \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0444\u0438\u043d\u0430\u043d\u0441\u043e\u0432\u043e\u0439 \u043e\u0442\u0447\u0451\u0442\u043d\u043e\u0441\u0442\u0438. \u0421\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043b\u0430\u0441\u044c \u0441\u043b\u043e\u0436\u043d\u0430\u044f \u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0432\u0437\u0430\u0438\u043c\u043e\u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432, \u0433\u0434\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0432\u043b\u0438\u044f\u0442\u044c \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0443 \u0434\u0435\u0441\u044f\u0442\u043a\u043e\u0432 \u0434\u0440\u0443\u0433\u0438\u0445. \u0417\u0430\u0434\u0430\u0447\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043b\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 \u0432\u0441\u0435 \u0444\u0430\u0439\u043b\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p><strong>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f:<\/strong><\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u0438\u0441\u043a \u043f\u043e \u0432\u0441\u0435\u043c \u0442\u0438\u043f\u0430\u043c Excel-\u0444\u0430\u0439\u043b\u043e\u0432 (XLSX, XLSM, XLS, XLSB)<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u0439 \u043e\u0431\u0445\u043e\u0434 \u043f\u0430\u043f\u043e\u043a<\/p>\n<\/li>\n<li>\n<p>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a \u0438 \u043f\u043e\u0432\u0440\u0435\u0436\u0434\u0451\u043d\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043d\u044f\u0442\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/p>\n<\/li>\n<\/ul>\n<h4>\u0422\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043d\u0430\u043b\u0438\u0437 \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u0432 Excel<\/h4>\n<p>\u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c\u0441\u044f \u0441 \u0444\u043e\u0440\u043c\u0430\u0442\u0430\u043c\u0438 \u0444\u0430\u0439\u043b\u043e\u0432:<\/p>\n<ol>\n<li>\n<p><strong>XLSX\/XLSM<\/strong> &#8212; Office Open XML, \u043f\u043e \u0441\u0443\u0442\u0438 ZIP-\u0430\u0440\u0445\u0438\u0432 \u0441 XML-\u0444\u0430\u0439\u043b\u0430\u043c\u0438<\/p>\n<\/li>\n<li>\n<p><strong>XLS<\/strong> &#8212; \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 Legacy Excel<\/p>\n<\/li>\n<li>\n<p><strong>XLSB<\/strong> &#8212; \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u0441 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e<\/p>\n<\/li>\n<\/ol>\n<p>\u0414\u043b\u044f \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u0432 (XLSX\/XLSM) \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u043e\u0434\u0445\u043e\u0434:<\/p>\n<pre><code class=\"powershell\"># \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0441\u0441\u044b\u043b\u043e\u043a \u0438\u0437 XLSX\/XLSM   function Get-ExcelLinksFromModernFormat {       param (           [string]$FilePath       )              try {           # \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e           $tempPath = [System.IO.Path]::GetTempPath() + [System.Guid]::NewGuid().ToString()           New-Item -ItemType Directory -Path $tempPath | Out-Null                      # \u041a\u043e\u043f\u0438\u0440\u0443\u0435\u043c Excel-\u0444\u0430\u0439\u043b \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e ZIP           $zipPath = Join-Path $tempPath \"temp.zip\"           Copy-Item -Path $FilePath -Destination $zipPath                      # \u0420\u0430\u0441\u043f\u0430\u043a\u043e\u0432\u044b\u0432\u0430\u0435\u043c           Expand-Archive -Path $zipPath -DestinationPath $tempPath                      # \u0418\u0449\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0438 \u0432 workbook.xml           $workbookXml = Join-Path $tempPath \"xl\\workbook.xml\"           if (Test-Path $workbookXml) {               [xml]$xml = Get-Content $workbookXml               $externalLinks = $xml.workbook.externalReferences.externalReference                              foreach ($link in $externalLinks) {                   # \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u0443\u0442\u044c \u043a \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u043c\u0443 \u0444\u0430\u0439\u043b\u0443 \u0438\u0437 rels                   $rId = $link.id                   $relsPath = Join-Path $tempPath \"xl\\_rels\\workbook.xml.rels\"                   [xml]$rels = Get-Content $relsPath                   $target = $rels.Relationships.Relationship |                        Where-Object { $_.Id -eq $rId } |                       Select-Object -ExpandProperty Target                                      [PSCustomObject]@{                       SourceFile = $FilePath                       LinkedFile = $target                       RelationType = \"External\"                   }               }           }       }       catch {           Write-Warning \"\u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0444\u0430\u0439\u043b\u0430 $FilePath : $_\"       }       finally {           # \u041e\u0447\u0438\u0441\u0442\u043a\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432           if (Test-Path $tempPath) {               Remove-Item -Path $tempPath -Recurse -Force           }       }   }   <\/code><\/pre>\n<p>\u0414\u043b\u044f \u0441\u0442\u0430\u0440\u044b\u0445 \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u0432 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c COM-\u043e\u0431\u044a\u0435\u043a\u0442 Excel:<\/p>\n<pre><code class=\"powershell\"># \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043e \u0441\u0442\u0430\u0440\u044b\u043c\u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u0430\u043c\u0438 \u0447\u0435\u0440\u0435\u0437 COM   function Get-ExcelLinksFromLegacyFormat {       param (           [string]$FilePath       )              $excel = $null       $workbook = $null              try {           $excel = New-Object -ComObject Excel.Application           $excel.Visible = $false           $excel.DisplayAlerts = $false                      # \u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0441 \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u043c\u0438 \u043c\u0430\u043a\u0440\u043e\u0441\u0430\u043c\u0438           $workbook = $excel.Workbooks.Open($FilePath, 0, $true)                      # \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0441\u0441\u044b\u043b\u043e\u043a           $links = @($workbook.LinkSources([Microsoft.Office.Interop.Excel.XlLink]::xlExcelLinks))                      foreach ($link in $links) {               [PSCustomObject]@{                   SourceFile = $FilePath                   LinkedFile = $link                   RelationType = \"External\"               }           }       }       catch {           Write-Warning \"\u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0444\u0430\u0439\u043b\u0430 $FilePath : $_\"       }       finally {           if ($workbook) {               $workbook.Close($false)           }           if ($excel) {               $excel.Quit()               [System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel) | Out-Null           }           [System.GC]::Collect()           [System.GC]::WaitForPendingFinalizers()       }   }   <\/code><\/pre>\n<h4>\u041c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430<\/h4>\n<p>\u0414\u043b\u044f \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u0443\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0444\u0430\u0439\u043b\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Jobs:<\/p>\n<pre><code class=\"powershell\">Codefunction Process-ExcelFilesInParallel {       param (           [string]$FolderPath,           [int]$MaxJobs = 3       )              $files = Get-ChildItem -Path $FolderPath -Recurse -Include \"*.xlsx\",\"*.xlsm\",\"*.xls\",\"*.xlsb\"       $jobs = @()       $results = @()              foreach ($file in $files) {           # \u0416\u0434\u0451\u043c, \u0435\u0441\u043b\u0438 \u0434\u043e\u0441\u0442\u0438\u0433\u043d\u0443\u0442 \u043b\u0438\u043c\u0438\u0442 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447           while ((Get-Job -State Running).Count -ge $MaxJobs) {               Start-Sleep -Milliseconds 500               Get-Job | Where-Object { $_.State -eq \"Completed\" } | ForEach-Object {                   $results += Receive-Job -Job $_                   Remove-Job -Job $_               }           }                      # \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043d\u043e\u0432\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443           $jobs += Start-Job -ScriptBlock {               param($file)               if ($file.Extension -in \".xlsx\",\".xlsm\") {                   Get-ExcelLinksFromModernFormat -FilePath $file.FullName               }               else {                   Get-ExcelLinksFromLegacyFormat -FilePath $file.FullName               }           } -ArgumentList $file       }              # \u041e\u0436\u0438\u0434\u0430\u0435\u043c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0437\u0430\u0434\u0430\u0447       Wait-Job -Job $jobs | Out-Null       $results += Get-Job | Receive-Job       Get-Job | Remove-Job              return $results   }  <\/code><\/pre>\n<h4>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 GUI \u043d\u0430 Windows Forms<\/h4>\n<p>\u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Windows Forms:<\/p>\n<pre><code class=\"powershell\">powershellCopy CodeAdd-Type -AssemblyName System.Windows.Forms   Add-Type -AssemblyName System.Drawing      function Create-ExcelLinksFinderGUI {       $form = New-Object System.Windows.Forms.Form       $form.Text = \"Excel Links Finder\"       $form.Size = New-Object System.Drawing.Size(800,600)       $form.StartPosition = \"CenterScreen\"          # \u041a\u043e\u043d\u0442\u0440\u043e\u043b\u044b \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u0430 \u0444\u0430\u0439\u043b\u0430-\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430       $sourceLabel = New-Object System.Windows.Forms.Label       $sourceLabel.Location = New-Object System.Drawing.Point(10,20)       $sourceLabel.Size = New-Object System.Drawing.Size(280,20)       $sourceLabel.Text = \"\u0412\u044b\u0431\u0435\u0440\u0438\u0442\u0435 \u0444\u0430\u0439\u043b \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0441\u0441\u044b\u043b\u043e\u043a:\"       $form.Controls.Add($sourceLabel)          $sourceTextBox = New-Object System.Windows.Forms.TextBox       $sourceTextBox.Location = New-Object System.Drawing.Point(10,40)       $sourceTextBox.Size = New-Object System.Drawing.Size(580,20)       $form.Controls.Add($sourceTextBox)          $sourceBrowseButton = New-Object System.Windows.Forms.Button       $sourceBrowseButton.Location = New-Object System.Drawing.Point(600,40)       $sourceBrowseButton.Size = New-Object System.Drawing.Size(75,20)       $sourceBrowseButton.Text = \"\u041e\u0431\u0437\u043e\u0440...\"       $sourceBrowseButton.Add_Click({           $fileDialog = New-Object System.Windows.Forms.OpenFileDialog           $fileDialog.Filter = \"Excel Files|*.xlsx;*.xlsm;*.xls;*.xlsb\"           if ($fileDialog.ShowDialog() -eq 'OK') {               $sourceTextBox.Text = $fileDialog.FileName           }       })       $form.Controls.Add($sourceBrowseButton)          # \u041f\u0440\u043e\u0433\u0440\u0435\u0441\u0441-\u0431\u0430\u0440       $progressBar = New-Object System.Windows.Forms.ProgressBar       $progressBar.Location = New-Object System.Drawing.Point(10,80)       $progressBar.Size = New-Object System.Drawing.Size(665,20)       $form.Controls.Add($progressBar)          # \u041b\u043e\u0433-\u0431\u043e\u043a\u0441       $logBox = New-Object System.Windows.Forms.RichTextBox       $logBox.Location = New-Object System.Drawing.Point(10,110)       $logBox.Size = New-Object System.Drawing.Size(665,400)       $logBox.ReadOnly = $true       $logBox.BackColor = [System.Drawing.Color]::White       $form.Controls.Add($logBox)          # \u041a\u043d\u043e\u043f\u043a\u0430 \u0437\u0430\u043f\u0443\u0441\u043a\u0430       $startButton = New-Object System.Windows.Forms.Button       $startButton.Location = New-Object System.Drawing.Point(10,520)       $startButton.Size = New-Object System.Drawing.Size(150,30)       $startButton.Text = \"\u041d\u0430\u0447\u0430\u0442\u044c \u043f\u043e\u0438\u0441\u043a\"       $startButton.Add_Click({           $logBox.Clear()           $progressBar.Value = 0                      if ([string]::IsNullOrEmpty($sourceTextBox.Text)) {               [System.Windows.Forms.MessageBox]::Show(\"\u0412\u044b\u0431\u0435\u0440\u0438\u0442\u0435 \u0444\u0430\u0439\u043b \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430!\")               return           }              $startButton.Enabled = $false           $sourceBrowseButton.Enabled = $false              # \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u043e\u0438\u0441\u043a \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435           $searchJob = [System.ComponentModel.BackgroundWorker]::new()           $searchJob.WorkerReportsProgress = $true           $searchJob.Add_DoWork({               param($sender, $e)               Search-ExcelLinks -SourceFile $sourceTextBox.Text -Progress $sender           })           $searchJob.Add_ProgressChanged({               param($sender, $e)               $progressBar.Value = $e.ProgressPercentage               $logBox.AppendText($e.UserState + \"`n\")               $logBox.ScrollToCaret()           })           $searchJob.Add_RunWorkerCompleted({               $startButton.Enabled = $true               $sourceBrowseButton.Enabled = $true               [System.Windows.Forms.MessageBox]::Show(\"\u041f\u043e\u0438\u0441\u043a \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d!\")           })           $searchJob.RunWorkerAsync()       })       $form.Controls.Add($startButton)          return $form   }   <\/code><\/pre>\n<h4>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a \u0438 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c<\/h4>\n<p>\u0412\u0430\u0436\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e \u0441\u0442\u0430\u043b\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"powershell\"># \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f   function Set-ExecutionPolicy {       try {           $currentPolicy = Get-ExecutionPolicy           if ($currentPolicy -eq \"Restricted\") {               # \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0441\u0430\u043c\u043e\u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0441\u0435\u0440\u0442\u0438\u0444\u0438\u043a\u0430\u0442             <\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\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-460097","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/460097","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=460097"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/460097\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=460097"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=460097"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=460097"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}