[CmdletBinding()] param( [string]$OutputPath, [switch]$Json ) $ErrorActionPreference = 'Stop' function Get-ExecutablePath { param([string]$Command) $text = $Command.Trim() if ($text -match '^\s*"([^"]+)"') { return $matches[1] } if ($text -match '^\s*(\S+\.(?:exe|bat|cmd|vbs|ps1))') { return $matches[1] } return ($text -split '\s+')[0] } $items = Get-CimInstance -ClassName Win32_StartupCommand $rows = foreach ($item in $items) { $command = [string]$item.Command $executable = Get-ExecutablePath -Command $command $expanded = [Environment]::ExpandEnvironmentVariables($executable) $exists = $false if (Test-Path -LiteralPath $expanded -PathType Leaf) { $exists = $true } elseif (Get-Command -Name $expanded -ErrorAction SilentlyContinue) { $exists = $true } [pscustomobject]@{ Name = $item.Name Location = $item.Location User = $item.User Executable = $expanded Exists = $exists Command = $command } } $rows = $rows | Sort-Object Exists, Name $missing = @($rows | Where-Object { -not $_.Exists }) Write-Host "Записей автозагрузки: $(@($rows).Count), с отсутствующим файлом: $($missing.Count)" if ($Json) { $text = $rows | ConvertTo-Json -Depth 4 } else { $text = $rows | Format-Table -Wrap | Out-String -Width 260 } if ($OutputPath) { $text | Set-Content -LiteralPath $OutputPath -Encoding UTF8 Write-Host "Отчёт сохранён: $OutputPath" } else { $text }