We have now been using the built-in package manager based on PowerShellGet. In the previous book called "Microsoft Exchange Server PowerShell Cookbook - Third Edition", we also used Chocolatey, where we can install third-party rich applications.
We'll take a look at how we can utilize chocolatey with Windows 2016 Server and Exchange 2016:
iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex
choco upgrade chocolatey
choco install notepadplusplus.install
choco upgrade notepadplusplus.install
choco uninstall notepadplusplus.install
choco install 7zip.install
choco upgrade 7zip.install
choco uninstall 7zip.install
In the preceding examples, we start by installing chocolatey. The second cmdlet is used for upgrading the existing installation of chocolatey. This is followed by two examples of how to install, upgrade, and uninstall two third-party application packages (Notepad++ and 7zip).
Chocolatey is great in many ways, but probably most companies, or at least enterprise companies, want to have their own "internal", more trusted and reliable repository, but still hosted on the internet.
Let's take a look at how this can be established. First let's sign up for an account at an optional provider.
In my case, I've used http://www.myget.org as the provider and created a feed when the account was created.
Now, let's see how the feed can be used as a repository. The feed that was created had an URL of: https://www.myget.org/F/tlpowershell/. Once it's created, we have to register it as a repository in PowerShell using the Register-PSRepository cmdlet:
Register-PSRepository -Name MyGet -SourceLocation `
https://www.myget.org/F/tlpowershell/api/v1 `
-PublishLocation https://www.myget.org/F/tlpowershell/ `
-InstallationPolicy Trusted
Find-Package -Source MyGet
Since the MyGet repository is brand new, there are currently no packages. So the next action is to upload a package to MyGet. For being able to upload a module, the module itself should have a file extension of .psm1 together with the module manifest using an extension of .psd1. In the manifest, it's necessary to include the values of Author and Description, but I want to recommend that the value of RootModule, ModuleVersion, and CompanyName, are also included. The following examples show how the manifest was created and also how the modules were published to MyGet.
New-ModuleManifest -Path ` C:\Windows\System32\WindowsPowerShell\v1.0\Modules\mailboxes.psd1` -Author "Jonas Andersson" -CompanyName "Testlabs, Inc." `
-RootModule "mailboxes" -Description `
"Module that lists mailboxes" -ModuleVersion "1.0"
Import-Module PowerShellGet
$PSGalleryPublishUri = ` 'https://www.myget.org/F/tlpowershell/api/v2/package'
$PSGallerySourceUri = ` 'https://www.myget.org/F/tlpowershell/api/v2'
Publish-Module -Name mailboxes -NuGetApiKey `
a2d5b281-c862-4125-9523-be42ef21f55a -Repository MyGet
Find-Package -Source MyGet
Install-Package -Name "mailboxes" -Source MyGet
Before ending this recipe, we might want to remove the repository for some reason. This is done simply by running the following cmdlet:
Unregister-PSRepository -Name MyGet