#Requires -Version 5.1 <# .SYNOPSIS Switch the target AMS NetID in the TwinCAT project. .DESCRIPTION Opens the solution, calls SetTargetNetId, saves. .PARAMETER NetId The new target AMS NetID (e.g. "10.0.0.106.1.1", "10.0.0.111.1.1"). .EXAMPLE .\tc-switch-target.ps1 -NetId 10.0.0.111.1.1 #> [CmdletBinding()] param( [Parameter(Mandatory)][string]$NetId, [string]$Solution = $null ) . "$PSScriptRoot\tc-common.ps1" if (-not $Solution) { $Solution = $script:DefaultSolution } New-Log $script:DefaultLogDir $LogFile = Join-Path $script:DefaultLogDir "switch-target.log" Write-Log "=== Switch Target NetId → $NetId ===" $LogFile $dte = Get-Dte -Visible:$false try { if (-not (Open-Solution -Dte $dte -Solution $Solution)) { throw "Solution did not open" } $sysMgr = Get-SysManager -Dte $dte $sysMgr.SetTargetNetId($NetId) Write-Log "SetTargetNetId($NetId) OK" $LogFile $sysMgr.SaveConfiguration() Write-Log "Saved" $LogFile Write-Log "=== Switch complete ===" $LogFile } finally { try { $dte.Quit() } catch { } }