From f411d48c80f1610e73a62136116a510c51f8b6a4 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Sun, 15 Mar 2026 16:27:09 +0000 Subject: [PATCH] fix: pre-load cached powershell modules so commands work without explicit Import-Module Co-Authored-By: Claude Opus 4.6 (1M context) --- backend/windmill-worker/src/pwsh_executor.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/backend/windmill-worker/src/pwsh_executor.rs b/backend/windmill-worker/src/pwsh_executor.rs index 1c3a74accc..212f65e80b 100644 --- a/backend/windmill-worker/src/pwsh_executor.rs +++ b/backend/windmill-worker/src/pwsh_executor.rs @@ -458,25 +458,26 @@ pub async fn handle_powershell_job( logs2.push_str("\n\n--- POWERSHELL CODE EXECUTION ---\n"); append_logs(&job.id, &job.workspace_id, logs2, db).await; - // make sure default (only allhostsallusers) modules are loaded, disable autoload (cache can be large to explore especially on cloud) and add /tmp/windmill/cache to PSModulePath + // Pre-load system modules and cached modules (e.g. WindmillClient), then disable + // autoloading so the large cache dir isn't scanned on every command invocation. #[cfg(unix)] let profile = format!( "$PSModuleAutoloadingPreference = 'None' $PSModulePathBackup = $env:PSModulePath -$env:PSModulePath = \"$PSHome/Modules\" +$env:PSModulePath = \"$PSHome/Modules:{}\" Get-Module -ListAvailable | Import-Module $env:PSModulePath = \"{}:$PSModulePathBackup\"", - *POWERSHELL_CACHE_DIR + *POWERSHELL_CACHE_DIR, *POWERSHELL_CACHE_DIR ); #[cfg(windows)] let profile = format!( "$PSModuleAutoloadingPreference = 'None' $PSModulePathBackup = $env:PSModulePath -$env:PSModulePath = \"C:\\Program Files\\PowerShell\\7\\Modules\" +$env:PSModulePath = \"C:\\Program Files\\PowerShell\\7\\Modules;{}\" Get-Module -ListAvailable | Import-Module $env:PSModulePath = \"{};$PSModulePathBackup\"", - *POWERSHELL_CACHE_DIR + *POWERSHELL_CACHE_DIR, *POWERSHELL_CACHE_DIR ); // NOTE: powershell error handling / termination is quite tricky compared to bash