如何卸载 PowerShell 模块?


要卸载 PowerShell 模块,我们可以直接使用 Uninstall-Module 命令,但模块不应该处于使用状态,否则会抛出错误。

当我们使用 Uninstall-Module 命令时,它可以从当前用户配置文件或所有用户配置文件中卸载模块。

Uninstall-Module 7Zip4PowerShell -Force -Verbose

另一种方法,

Get-InstalledModule 7Zip4Powershell | Uninstall-Module -Force -Verbose

如果在 PowerShell 中安装了同一模块的多个版本,并且想要卸载所有版本,则使用-AllVersions 参数。

Uninstall-Module 7Zip4PowerShell -AllVersions -Force -Verbose

如果要卸载特定版本,可以使用 -RequiredVersion

Uninstall-Module 7Zip4PowerShell -RequiredVersion 1.5.0 -Force -Verbose

要在远程计算机上卸载,请使用 Invoke-Command 方法。

Invoke-Command -ComputerName RemoteComputer1 -ScriptBlock {
   Uninstall-Module 7Zip4PowerShell -RequiredVersion 1.5.0 -Force -Verbose
}

更新于:2021 年 3 月 18 日

18K+ 浏览次数

开启你的职业生涯

完成课程以获得认证

开始学习
广告
© . All rights reserved.