删除模块还会尝试删除PackageManagement

时间:2019-07-01 21:32:14

标签: powershell

在使用Remove-Module的PowerShell会话中首次删除自定义模块时,也会尝试删除模块PackageManagement。我不知道这种行为的来源。

我一直在构建用于与内部API交互的PowerShell模块。

该模块的布局与PoshDog项目非常相似:https://github.com/simnyc/poshdog/tree/master/PoshDog

存在相同问题的框架项目位于以下位置:https://github.com/Christophoclese/powershell-module-template

PS C:\Users\cbarton\Desktop\GitHub\ModuleTemplate> .\Test-Module.ps1
WARNING: Did not find an installed version of ModuleTemplate-test. Are you testing with Test-Module.ps1?

Module ModuleTemplate-test (0.0.8) loaded.
Please contact someauthor@somedomain.com with questions.

PS C:\Users\cbarton\Desktop\GitHub\ModuleTemplate> remove-module ModuleTemplate-test -Verbose
VERBOSE: Performing the operation "Remove-Module" on target "Microsoft.PowerShell.PackageManagement (Path: 'C:\Program
Files\WindowsPowerShell\Modules\PackageManagement\1.3.1\fullclr\Microsoft.PowerShell.PackageManagement.dll')".
VERBOSE: Performing the operation "Remove-Module" on target "Microsoft.PackageManagement (Path: 'C:\Program
Files\WindowsPowerShell\Modules\PackageManagement\1.3.1\fullclr\Microsoft.PackageManagement.dll')".
VERBOSE: Performing the operation "Remove-Module" on target "PackageManagement (Path: 'C:\Program
Files\WindowsPowerShell\Modules\PackageManagement\1.3.1\PackageManagement.psm1')".
VERBOSE: Performing the operation "Remove-Module" on target "ModuleTemplate-test (Path:
'C:\Users\cbarton\Documents\WindowsPowerShell\Modules\ModuleTemplate-test\ModuleTemplate-test.psm1')".
remove-module : Unable to remove the module 'PackageManagement' because it is required by 'PowerShellGet'. Add the
Force parameter to your command to remove the module.
At line:1 char:1
+ remove-module ModuleTemplate-test -Verbose
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (PackageManagement:PSModuleInfo) [Remove-Module], InvalidOperationExce
   ption
    + FullyQualifiedErrorId : Modules_ModuleIsRequired,Microsoft.PowerShell.Commands.RemoveModuleCommand

尽管出现了错误,实际上还是从当前会话中删除了该模块。

我希望不会出现任何错误,并且删除模块不会导致PowerShell尝试卸载PackageManagement。

我如何深入了解为什么PowerShell代表我执行此操作?

0 个答案:

没有答案