From 6bb6f25a6219792ca16063fb3a58dcda1ea4adcb Mon Sep 17 00:00:00 2001 From: 1plus <122733139+Chen1Plus@users.noreply.github.com> Date: Thu, 12 Sep 2024 18:17:58 +0800 Subject: [PATCH] fix: error when no envVars --- wmod.psm1 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/wmod.psm1 b/wmod.psm1 index 6ba407e..ec49e46 100644 --- a/wmod.psm1 +++ b/wmod.psm1 @@ -33,8 +33,10 @@ function Wmod-Load { $env:PATH = $Path + $env:PATH # add environment variables - $EnvVars.Keys | ForEach-Object { - New-Item -Path "Env:\$_" -Value $EnvVars[$_] + if ($EnvVars) { + $EnvVars.Keys | ForEach-Object { + New-Item -Path "Env:\$_" -Value $EnvVars[$_] + } } $script:Wmod_Loaded += $modulePath @@ -82,8 +84,10 @@ function Unload-ByPath { $env:PATH = $env:PATH.Replace($Path, '') # remove environment variables - $EnvVars.Keys | ForEach-Object { - Remove-Item -Path "Env:\$_" + if ($EnvVars) { + $EnvVars.Keys | ForEach-Object { + Remove-Item -Path "Env:\$_" + } } $script:Wmod_Loaded = $script:Wmod_Loaded | Where-Object { $_ -ne $modulePath }