#Requires -Version 5.1 [CmdletBinding()] param( [string]$Solution = $null ) . "$PSScriptRoot\tc-common.ps1" if (-not $Solution) { $Solution = $script:DefaultSolution } New-Log $script:DefaultLogDir $LogFile = Join-Path $script:DefaultLogDir "list-commands.log" function Write-Log($Message) { $line = "[{0}] {1}" -f (Get-Date -Format 'HH:mm:ss'), $Message Write-Host $line Add-Content -Path $LogFile -Value $line -Encoding UTF8 } try { $dte = New-Object -ComObject TcXaeShell.DTE.17.0 -ErrorAction Stop } catch { Write-Log "FATAL: Cannot create DTE: $_" exit 1 } $dte.MainWindow.Visible = $true try { $dte.Solution.Open($Solution) for ($i = 1; $i -le 120; $i++) { Start-Sleep -Seconds 1 if ($dte.Solution.IsOpen) { break } } Write-Log "Solution open: $($dte.Solution.IsOpen)" $sysMgr = $null for ($i = 1; $i -le 40; $i++) { try { $sysMgr = $dte.Solution.Projects.Item(1).Object if ($sysMgr) { break } } catch {} Start-Sleep -Seconds 3 } Write-Log "SysManager: $(if ($sysMgr) { 'OK' } else { 'null' })" Write-Log "Listing DTE commands matching 'TwinCAT'..." foreach ($cmd in $dte.Commands) { try { $name = $cmd.Name if ($name -like '*TwinCAT*') { Write-Log " Command: $name" } } catch {} } Write-Log "Done." } finally { try { $dte.Quit() } catch {} }