![Windows Server 2016 Automation with PowerShell Cookbook(Second Edition)](https://wfqqreader-1252317822.image.myqcloud.com/cover/733/36700733/b_36700733.jpg)
How it works...
In step 1, you review the cmdlets available in the PackageManagement module:
![](https://epubservercos.yuewen.com/7D2E6F/19470404008937606/epubprivate/OEBPS/Images/03d8d068-772f-4023-bca3-604f835f2910.png?sign=1739396214-aYMqlT0U3EdVOw7M1OLFpnCHP8ro6pxN-0-d708b68c3dddd6ca9ac6da60a1a907fb)
In step 2, you use the Get-PackageProvider cmdlets to display the currently installed package providers:
![](https://epubservercos.yuewen.com/7D2E6F/19470404008937606/epubprivate/OEBPS/Images/9f35f51d-6aa9-4e7c-9379-73a7aea29a84.png?sign=1739396214-UcCfBpyQKgxEvYYipiawOfcQ3sulJWl2-0-d8b22233402b65693ed8e1a90aa9e5bb)
In step 3, you use Get-Package with the -ProviderName parameter to review packages installed via the msi, msu, and Programs package providers:
![](https://epubservercos.yuewen.com/7D2E6F/19470404008937606/epubprivate/OEBPS/Images/84050261-3e34-4f1f-8648-8f15b5620b24.png?sign=1739396214-Lakfi04YqwoigIQSJX5GrZFGe5xUfgN3-0-3a48d3cabdbc800cd79b474f655bf2f0)
In step 4, review the NuGet provider:
![](https://epubservercos.yuewen.com/7D2E6F/19470404008937606/epubprivate/OEBPS/Images/1bef9cf9-bc4a-45b8-8bf1-9521a900da54.png?sign=1739396214-6WrqUelHMGuQrEDKJaHEP88qmKliR7Be-0-2a9d820ece86e50add661793c34d8fb4)
In step 5, search for other package providers:
![](https://epubservercos.yuewen.com/7D2E6F/19470404008937606/epubprivate/OEBPS/Images/2687924a-c1f6-495e-9c3c-6ccccb707863.png?sign=1739396214-pVE5QqsAxYxlHF00wEOXcaoSEdmUchBa-0-2318bf929f26f26fbd579d378cc3b533)
In step 6, you use Install-PackageProvider to install the Chocolatey provider. Since it is untrusted as a public source, you must approve the installation (at your own risk and responsibility):
![](https://epubservercos.yuewen.com/7D2E6F/19470404008937606/epubprivate/OEBPS/Images/406c7f4f-a0db-466a-8fe4-dbc925cc1483.png?sign=1739396214-CQnIB0fmAQXbkOqH3dHMiTVX7eaGPRwS-0-a46896cad3c3539a1d1020b27af0eb59)
In this example, you run Install-PackageProvider from within the ISE. By default, this pops up a confirmation dialog. If you run this cmdlet from the PowerShell console, you see a prompt there. You can suppress these confirmation requests by including the parameter -Confirm:$False.
In step 7, you verify Chocolatey is now installed as a package provider:
![](https://epubservercos.yuewen.com/7D2E6F/19470404008937606/epubprivate/OEBPS/Images/23b62105-6df4-4454-921c-0bfdce5c3c51.png?sign=1739396214-tWtqKFtkhQU6h3KMH9q9C3Cq3XNRnCwM-0-b2b88ce045d1206b48163fcd9fc79b04)
In step 8, retrieve a list of available software packages from the ChocolateyPackageProvider, store as a variable, and count the available packages:
![](https://epubservercos.yuewen.com/7D2E6F/19470404008937606/epubprivate/OEBPS/Images/5d06c885-f9bc-42ed-ac0a-5c444d0f7585.png?sign=1739396214-NOb0gdKBDKFbC7zEjGq8jpgI5o4TAS9V-0-275911456457b58fb6ea21daf68ddfcc)
In step 9, pipe the variable to Out-GridView and use the filter feature to explore what is available. This example is filtering for the Sysinternals package:
![](https://epubservercos.yuewen.com/7D2E6F/19470404008937606/epubprivate/OEBPS/Images/4680f2cd-a69c-445e-bb65-f9b09c55dc07.png?sign=1739396214-JMR70MA6LBB5xX3yQSzbDy9p9LOMkIMG-0-242fdfb857ffba3af12122683e602340)
In step 10, you install this package (or any package you choose):
![](https://epubservercos.yuewen.com/7D2E6F/19470404008937606/epubprivate/OEBPS/Images/d2defcf3-1f61-46ac-a32a-ee35f0ce3eae.png?sign=1739396214-eJyWUccK3z8WxbRXMaTLKbyUQaS2kHfj-0-ce44f3264191ed3549de9c161ee52733)
In step 11, you review the installed Chocolatey packages, and the files contained within the sysinternals package folder:
![](https://epubservercos.yuewen.com/7D2E6F/19470404008937606/epubprivate/OEBPS/Images/71f86785-5d46-483a-a184-30b1da82923c.png?sign=1739396214-fKyebUvqtKSIYWltjNkHzD8MGIjNXhIY-0-c02ebc846aee4a1749b51699de48472d)
In step 12, run any Sysinternals command, for example, PsInfo.Exe :
![](https://epubservercos.yuewen.com/7D2E6F/19470404008937606/epubprivate/OEBPS/Images/3839e225-1424-405a-a8f8-665ca4f72965.png?sign=1739396214-FXT8Gl5So8a1JRl6rhMTAQgYMajfzigr-0-6042617df5676d4f9b71c0ab0d84e751)
In step 13, you enumerate the installed packages with Get-Package. As time goes by, packages can be updated with bug fixes, new features, and so on. You can update all the installed packages if any updates exist, as follows:
![](https://epubservercos.yuewen.com/7D2E6F/19470404008937606/epubprivate/OEBPS/Images/92eef698-30ea-436a-b2e1-2d94dc04b2cb.png?sign=1739396214-XNrYkzCDZuNCTmefDi1fS8ilocComdSE-0-318a229d57f5e2474e3d4e48ac54a808)