![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=1739395916-YslwpbrJ8zqEHLIqLEbBh1mtcQWHB2n5-0-329eb1cbe9d2d2e6bd877838f1072763)
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=1739395916-z8jGP72FbTRlVcMNZxNrAyzlUJVcoVMe-0-216f869e6c51fa95669114f69a6fb474)
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=1739395916-tAZPQfRyg6q5ys9JkHVuu00CIH10cHt2-0-a16020879928a7e9e5a9d50142107b87)
In step 4, review the NuGet provider:
![](https://epubservercos.yuewen.com/7D2E6F/19470404008937606/epubprivate/OEBPS/Images/1bef9cf9-bc4a-45b8-8bf1-9521a900da54.png?sign=1739395916-zUP9GwXtHuerweVCBkzYkehTyIyzFC3H-0-8d0ea4107230d18528703ad06d18d05e)
In step 5, search for other package providers:
![](https://epubservercos.yuewen.com/7D2E6F/19470404008937606/epubprivate/OEBPS/Images/2687924a-c1f6-495e-9c3c-6ccccb707863.png?sign=1739395916-GIpOoko83W5h3oHNAoC2Z3m87U9QxSeZ-0-9c05fa107db79098d25d3c890acafdd5)
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=1739395916-yn6eCQsYhd7g17eZHwZVq4GPZNQZdnX1-0-dc81963a4947092e8c7d1219253dcb95)
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=1739395916-gLAPxdRtG3ilonsoEbg3Fpm5OBlGKywu-0-f254b5fc4c1185c3324c5afaa0c3fed8)
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=1739395916-cH33nwDpUPUiKKdO3utcyWtssd29guFj-0-8a47103219ff36b2de804f7a5aa62c40)
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=1739395916-mZjVicew7hFJgG1GB1CsCE1ASmbjrlsE-0-ae296158beac0a24568cdb1956313b8a)
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=1739395916-M9khAAomDnwtkNGoyq3SpjGqRZ4KwyDr-0-eb6b71ad52239fe15887c79c9e2c3d90)
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=1739395916-wU0A4y3F6f8F9JOvr41bU88m6KGVbKyZ-0-4193861b319465678629efb01e7d77bd)
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=1739395916-Gx1SSsm9VawpLRQHq2gfCoPfls4eB5aW-0-490731cf3c98e0a2ebc6d4b1d26ae1c1)
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=1739395916-Z9MqFS1B9EMS0iNEDFIRt8NItDfQfzmW-0-0456545fe2300eae32d1d6662b6bcbd7)