提交 87f96484 authored 作者: 陈泽健's avatar 陈泽健

fix: 修复MiddlewareCheck模块导入ContainerCheck时缺少-Global参数导致函数作用域丢失的问题,同时抑制模块加载时的引擎警告

上级 1bdf43f4
...@@ -277,6 +277,11 @@ $Global:OldPlatformUpythonLogs = @( ...@@ -277,6 +277,11 @@ $Global:OldPlatformUpythonLogs = @(
# 获取模块目录路径 # 获取模块目录路径
$ModulePath = Join-Path $global:SCRIPT_DIR "modules" $ModulePath = Join-Path $global:SCRIPT_DIR "modules"
# 临时抑制 PowerShell 模块导入引擎警告
# (如函数名含下划线/未批准动词导致 "受限字符"、"未批准动词" 提示,模块加载结束后恢复)
$script:OldWarningPreference = $WarningPreference
$WarningPreference = 'SilentlyContinue'
# 强制卸载已加载的模块(确保使用最新版本) # 强制卸载已加载的模块(确保使用最新版本)
$ModulesToUnload = @("ServiceCheck", "Common", "DNSCheck", "ServerResourceAnalysis", "NTPCheck", "ContainerCheck", "ConfigIPCheck", "MiddlewareCheck", "AndroidCheck", "LogExport", "Report", "ServerProfile", "DataBackup", "FilePermission", "ShellAdapter", "SecurityCheck") $ModulesToUnload = @("ServiceCheck", "Common", "DNSCheck", "ServerResourceAnalysis", "NTPCheck", "ContainerCheck", "ConfigIPCheck", "MiddlewareCheck", "AndroidCheck", "LogExport", "Report", "ServerProfile", "DataBackup", "FilePermission", "ShellAdapter", "SecurityCheck")
foreach ($ModuleName in $ModulesToUnload) { foreach ($ModuleName in $ModulesToUnload) {
...@@ -418,6 +423,9 @@ if ($missingFunctions.Count -gt 0) { ...@@ -418,6 +423,9 @@ if ($missingFunctions.Count -gt 0) {
Write-Host "[模块加载] 所有模块函数已成功导入并可用" -ForegroundColor Green Write-Host "[模块加载] 所有模块函数已成功导入并可用" -ForegroundColor Green
} }
# 恢复模块导入时的警告级别(模块加载完成)
$WarningPreference = $script:OldWarningPreference
# ================================ # ================================
# 所有检测函数已按职责拆分到 modules/ 目录 # 所有检测函数已按职责拆分到 modules/ 目录
......
...@@ -59,7 +59,7 @@ if (Test-Path $CommonModulePath) { ...@@ -59,7 +59,7 @@ if (Test-Path $CommonModulePath) {
# 导入依赖的 ContainerCheck 模块 # 导入依赖的 ContainerCheck 模块
$ContainerCheckModulePath = Join-Path $ModuleDir "ContainerCheck.psm1" $ContainerCheckModulePath = Join-Path $ModuleDir "ContainerCheck.psm1"
if (Test-Path $ContainerCheckModulePath) { if (Test-Path $ContainerCheckModulePath) {
Import-Module $ContainerCheckModulePath -Force -ErrorAction SilentlyContinue Import-Module $ContainerCheckModulePath -Force -Global -ErrorAction SilentlyContinue
} }
#endregion Module Initialization #endregion Module Initialization
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论