This folder contains modular PowerShell scripts that are automatically discovered and executed by the main twincat-deploy.ps1 script. The main script has zero hardcoded references - it dynamically finds and runs whatever scripts you place here.
The twincat-deploy.ps1 script:
- Scans for numbered phase folders (
01-,02-,03-...) - Discovers all
.ps1files in each phase - Executes them in numerical order automatically
- No hardcoding - completely plug-and-play extensible
POWERSHELL SCRIPTS/
├── Shared/
│ └── TwinCATDeployUtils.psm1 # Shared utilities module
├── 01-PackageManagement/ # TwinCAT package installation
│ ├── 01-CopyPackagesOffline.ps1
│ ├── 02-AddPackageSource.ps1
│ └── 03-InstallPackages.ps1
├── 02-SystemConfiguration/ # Windows system configuration
│ ├── 01-SetCoreIsolation.ps1
│ ├── 02-RenameEthernetAdapters.ps1
│ └── 03-InstallRealtimeDriver.ps1
├── 03-TwinCATConfiguration/ # TwinCAT-specific configuration
│ ├── 01-SetTwinCATRunModeOnBoot.ps1
│ ├── 02-CopyTwinCATBoot.ps1
│ ├── 03-CopyHMIProject.ps1
│ └── 04-CopyHMIConfig.ps1
├── 04-UIClientSetup/ # UI Client configuration
│ ├── 01-ConfigureTF1200.ps1
│ └── 02-ConfigureTF1200AutoLaunch.ps1
└── 99-SystemRestart/ # System restart (if needed)
└── 01-RebootSystem.ps1
Automatic Discovery Process:
twincat-deploy.ps1scans for phase folders matching^\d+pattern- Sorts phases numerically:
01-,02-,03-... - For each phase, finds all
.ps1files and sorts numerically - Executes each script, checking return value
- Aborts entire deployment if any script returns
$false
Example execution order:
01-PackageManagement/01-CopyPackagesOffline.ps1
01-PackageManagement/02-AddPackageSource.ps1
01-PackageManagement/03-InstallPackages.ps1
02-SystemConfiguration/01-SetCoreIsolation.ps1
02-SystemConfiguration/02-RenameEthernetAdapters.ps1
... and so on
mkdir "05-CustomPhase"# Create script in existing or new phase
files/POWERSHELL SCRIPTS/05-CustomPhase/01-MyCustomScript.ps1- Return Value: Must return
$true(success) or$false(failure) - Naming: Follow
01-ScriptName.ps1convention for ordering - Dependencies: Use shared functions from
TwinCATDeployUtils.psm1
# @Title: Custom Operation
# @Description: Does something custom for deployment
# @Phase: 05-CustomPhase
# @Order: 01
# @Dependencies: None
# @Optional: false
Write-Log "Performing custom operation..." "SUCCESS"
# Use shared functions:
# - Write-Log for logging
# - Get-FilesPath for files directory
# - Get-ScriptRoot for script root directory
try {
# Your custom logic here
$result = $true
if ($result) {
Write-Log " ✓ Custom operation completed successfully" "SUCCESS"
return $true
} else {
Write-Log " ✗ Custom operation failed" "ERROR"
return $false
}
} catch {
Write-Log " ✗ Custom operation error: $_" "ERROR"
return $false
}All scripts have access to these functions from TwinCATDeployUtils.psm1:
Write-Log $Message $Level- Unified logging with colors and file outputGet-FilesPath- Returns path to files directoryGet-ScriptRoot- Returns main script root directoryTest-IsElevated- Checks for administrator privileges
Include metadata in script comments for documentation:
# @Title: Human-readable title
# @Description: Detailed description
# @Phase: Phase folder name
# @Order: Execution order within phase
# @Dependencies: Required previous scripts
# @Optional: true/false🔄 True Extensibility
- Drop new
.ps1files anywhere in the structure - Main script automatically discovers and runs them
- Zero changes needed to
twincat-deploy.ps1
📦 Modular Design
- Each script handles single responsibility
- Easy to test, debug, and maintain individual steps
- Reusable across different deployments
🎯 Automatic Ordering
- Numerical naming ensures predictable execution order
- Easy to insert new steps between existing ones (e.g.,
01.5-NewStep.ps1)
🛡️ Error Handling
- Deployment stops immediately on any script failure
- Comprehensive logging for troubleshooting
- Clean abort prevents partial installations
⚙️ Reboot Control
- Want to reboot? Keep the
99-SystemRestart/01-RebootSystem.ps1script - Don't want to reboot? Delete or rename the
99-SystemRestartfolder - No parameters needed - presence/absence of script controls behavior
Same as always - no changes needed:
.\twincat-deploy.ps1 # Uses modular approach automaticallyControl reboot behavior by file presence:
# To skip reboot - remove or rename the restart folder
mv "files/POWERSHELL SCRIPTS/99-SystemRestart" "files/POWERSHELL SCRIPTS/99-SystemRestart.disabled"
# To enable reboot - ensure the restart folder exists
mv "files/POWERSHELL SCRIPTS/99-SystemRestart.disabled" "files/POWERSHELL SCRIPTS/99-SystemRestart"The magic happens automatically - the main script discovers and executes whatever scripts you've placed in the numbered folders!
More System Configuration Examples: For additional Windows system configuration scripts and automation examples, visit the official Beckhoff repository: 🔗 Beckhoff Windows Tools
This repository contains PowerShell scripts for various TwinCAT and Windows configuration tasks that can be adapted for use in your modular deployment structure.
All sample code provided by Beckhoff Automation LLC are for illustrative purposes only and are provided "as is" and without any warranties, express or implied. Actual implementations in applications will vary significantly. Beckhoff Automation LLC shall have no liability for, and does not waive any rights in relation to, any code samples that it provides or the use of such code samples for any purpose.