我们在一个部署 PowerShell 脚本中使用一些 PowerShell 模块。使用以下命令,我们将模块(即 XXXX)安装到 "C:\Program Files\WindowsPowerShell\Modules" 中。
Install-Module -Name "XXXX" -AllowClobber -RequiredVersion "XXXX" -Repository "XXXX" -Scope AllUsers
现在,一旦我们使用了该模块的功能,我们将使用以下命令在部署脚本结束时卸载它。Remove-Module -Name "XXXX" -force
Uninstall-Module -Name "XXXX" -AllVersions -force
但是这个卸载模块命令会给出以下错误。
WARNING: The version '###' of module 'XXXX' is currently in use. Retry the operation after closing the
applications.
PackageManagement\Uninstall-Package : Module 'XXXX' is in currently in use.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:2046 char:21
+ ... $null = PackageManagement\Uninstall-Package @PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Microsoft.Power...ninstallPackage:UninstallPackage) [Uninstall-Packag
e], Exception
+ FullyQualifiedErrorId : ModuleIsInUse,Uninstall-Package,Microsoft.PowerShell.PackageManagement.Cmdlets.Uninstall
Package
有人有解决这个问题的想法吗?