IoTPowerShellAgent is a PowerShell executor service integrated with Azure IoT Hub, designed to run as a Windows Service.
iot_powershell_agent/
├── backend/ # Bicep templates for Azure backend resources
├── ci/ # Continuous integration scripts/pipelines
├── config/ # Configuration files
│ └── appsettings.json
├── docs/ # Documentation
│ └── PROJECT_STRUCTURE.md
├── src/
│ └── IoTPowerShellAgent/ # Main project source code
│ ├── Core/ # Core domain models and services
│ │ ├── PowerShellExecutionResult.cs
│ │ ├── SettingsService.cs
│ │ ├── LogOutputType.cs
│ │ └── EHExceptionRecord.cs
│ ├── PowerShell/ # PowerShell host implementations
│ │ ├── PowerShellExecutor.cs
│ │ ├── DefaultHost.cs
│ │ ├── DefaultHostUserInterface.cs
│ │ └── DefaultHostRawUserInterface.cs
│ ├── IoT/ # Azure IoT Hub integration
│ │ └── IoTHubService.cs
│ ├── Services/ # Windows Service implementation
│ │ └── PowerShellExecutorService.cs
│ ├── Utilities/ # Utility classes and helpers
│ │ ├── JsonObject.cs # JSON conversion utilities (embedded from powershellruntimeextension)
│ │ ├── ConvertToJsonContext.cs
│ │ ├── ProcessUtil.cs
│ │ └── WindowsApiInterop.cs
│ ├── Program.cs # Application entry point
│ └── IoTPowerShellAgent.csproj # Project file
├── .github/ # GitHub Actions workflows
├── .vscode/ # VS Code settings
├── CONTRIBUTING.md # Contribution guidelines
├── Directory.Build.props # Shared build properties
├── LICENSE # Project license
├── LogicalDiagram.md # Architecture logical diagram
└── README.md # Root project documentation
- IoTPowerShellAgent - Root namespace (Program.cs)
- IoTPowerShellAgent.Core - Core domain models, settings, and result types
- IoTPowerShellAgent.PowerShell - PowerShell host and executor implementations
- IoTPowerShellAgent.IoT - Azure IoT Hub client and integration
- IoTPowerShellAgent.Services - Windows Service implementation
- IoTPowerShellAgent.Utilities - Utility classes including JSON conversion, process management, and Windows API interop
- PowerShellExecutionResult: Execution result model with JSON conversion support
- SettingsService: Singleton service for application configuration
- LogOutputType: Enumeration for log output types
- PowerShellExecutor: Main executor for PowerShell scripts with stream handling
- DefaultHost: Custom PSHost implementation
- DefaultHostUserInterface: Custom PSHostUserInterface for non-interactive execution
- IoTHubService: Manages Azure IoT Hub connections, direct methods, and telemetry
- JsonObject: Embedded PowerShell JSON conversion utilities (formerly in powershellruntimeextension)
- Converts PowerShell objects to/from JSON
- Supports complex PowerShell object structures
- Used for API integration and workflow systems
- ProcessUtil: Process management and performance monitoring using P/Invoke
- WindowsApiInterop: Windows API declarations for performance-critical operations
Configuration is managed through config/appsettings.json and loaded via SettingsService. The service will check multiple locations for the configuration file to support different deployment scenarios.
dotnet build src/IoTPowerShellAgent/IoTPowerShellAgent.csprojThe service can run in two modes:
- Windows Service - Production mode (requires service installation)
- Console Mode - Development/debugging mode (when run interactively)