上QQ阅读APP看书,第一时间看更新
How to do it...
You use the cmdlets within the PackageManagement module to explore the capabilities it provides.
- Review the cmdlets in the PackageManagement module:
Get-Command -Module PackageManagement
- Review the installed providers with Get-PackageProvider:
Get-PackageProvider | Select-Object -Property Name, Version
- The provider list includes msi, msu, and Programs package providers. These providers expose applications and updates installed on your computer which you can explore:
Get-Package -ProviderName msi |
Select-Object -ExpandProperty Name
Get-Package -ProviderName msu |
Select-Object -ExpandProperty Name
Get-Package -ProviderName Programs |
Select-Object -ExpandProperty Name
- The NuGet source contains developer library packages. This functionality is outside the scope of this book, but worth exploring if you do Windows or web development:
Get-PackageProvider -Name NuGet
- There are also other package providers you can explore:
Find-PackageProvider |
Select-Object -Property Name,Summary |
Format-Table -Wrap -AutoSize
- Notice Chocolatey, which is a very useful tool for Windows administrators and power users. Those with some Linux background may think of Chocolatey as apt-get for Windows. You cannot use this provider until you install it and confirm the installation:
Install-PackageProvider -Name Chocolatey -Verbose
- Verify Chocolatey is now in the list of installed providers:
Get-PackageProvider | Select-Object Name,Version
- Look for available software packages from the Chocolatey package provider. Store these in a variable so you don't request the collection more than once, and explore it:
$AvailableChocolateyPackages = `
Find-Package -ProviderName Chocolatey
# How many software packages are available at Chocolatey?
$AvailableChocolateyPackages | Measure-Object
- Pipe to Out-GridView to search for interesting software packages from Chocolatey:
$AvailableChocolateyPackages |
Sort-Object Name,Version |
Select-Object Name, Version, Summary |
Out-GridView
- Install one or more packages. sysinternals is a good example to use. Use -Verbose to get details on the installation:
Install-Package -ProviderName Chocolatey `
-Name sysinternals `
-Verbose
- Review installed Chocolatey packages, stored to C:\chocolatey\ by default, this path is stored in the $env:ChocolateyPath environment variable. Then review the executable files included with the sysinternals package:
Get-ChildItem -Path $env:ChocolateyPath\lib |
Select-Object -Property Name
Get-ChildItem -Path `
$env:ChocolateyPath\lib\sysinternals.2016.11.18\tools `
-Filter *.exe |
Select-Object -Property Name
- Run any installed command included with sysinternals:
$PSInfoCommand = `
‘C:\Chocolatey\lib\sysinternals.2016.11.18\tools\PsInfo.exe’
Invoke-Expression -Command $PSInfoCommand
- Installed packages are enumerated with Get-Package and updated using the same command to install them, Install-Package:
Get-Package -ProviderName Chocolatey |
Install-Package -Verbose