最安全的方法是完全专注于通过 Install-Module 安装的模块,因为这样您永远不会意外删除 Windows 或属于其他软件产品的一部分的模块。
这行代码列出了由 Install-Module 安装的所有模块,并让您选择要(永久)删除的模块。
1 2 3 4
Get-InstalledModule | Out-GridView-Title'Select module(s) to permanently delete'-PassThru | Out-GridView-Title'Do you REALLY want to remove the modules below? CTRL+A and OK to confirm'-PassThru | Uninstall-Module
# this is the URL we got: $URLRaw = 'http://go.microsoft.com/fwlink/?LinkID=135173' # we do not allow automatic redirection and instead read the information # returned by the webserver ourselves: $page = Invoke-WebRequest-Uri$URLRaw-UseBasicParsing-MaximumRedirection0-ErrorAction Ignore $target = $page.Headers.Location
$URLRaw = 'https://github.com/PowerShell/PowerShell/releases/latest' # we do not allow automatic redirection and instead read the information # returned by the webserver ourselves: $page = Invoke-WebRequest-Uri$URLRaw-UseBasicParsing-MaximumRedirection0-ErrorAction Ignore $realURL = $page.Headers.Location $version = Split-Path-Path$realURL-Leaf
"PowerShell 7 latest version: $version"
同样的方法也适用于 PowerShell Gallery 模块:
1 2 3 4 5 6 7 8 9 10
# name of a module published at powershellgallery.com $ModuleName = 'ImportExcel'
$URL = "https://www.powershellgallery.com/packages/$ModuleName" # get full URL (including latest version): $page = Invoke-WebRequest-Uri$URL-UseBasicParsing-MaximumRedirection0-ErrorAction Ignore $realURL = $page.Headers.Location # return version only: $latest = Split-Path-Path$realURL-Leaf "Module $ModuleName latest version: $latest"
Status Name DisplayName --------------------- Running AdobeARMservice Adobe Acrobat Update Service Running AgentShellService Spiceworks Agent Shell Service Running Appinfo Application Information Running AppMgmt Application Management ...
它的使用非常易于使用,最重要的是,输出强类型的对象,因此您仍然可以访问其属性
1 2 3 4 5 6 7 8 9 10
PS> Get-Service | grep running | Select-Object Name, StartType, Status