При первом удалении пользовательского модуля в сеансе PowerShell с использованием Remove-Module также выполняется попытка удаления модуля PackageManagement. Я не понимаю, откуда это поведение.
Я собирал модуль PowerShell для взаимодействия с внутренним API.
Макет модуля очень похож на проект 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 выполняет это действие от моего имени?