Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Microsoft Exchange Server Powershell Cookbook (Update)
  • Table Of Contents Toc
Microsoft Exchange Server Powershell Cookbook (Update)

Microsoft Exchange Server Powershell Cookbook (Update)

By : Andersson, Mike Pfeiffer
5 (1)
close
close
Microsoft Exchange Server Powershell Cookbook (Update)

Microsoft Exchange Server Powershell Cookbook (Update)

5 (1)
By: Andersson, Mike Pfeiffer

Overview of this book

This book is for messaging professionals who want to build real-world scripts with Windows PowerShell 5 and the Exchange Management Shell. If you are a network or systems administrator responsible for managing and maintaining Exchange Server 2013, you will find this highly useful.
Table of Contents (17 chapters)
close
close

Working with script repositories

Windows Management Framework Version 5 includes a package manager called PowerShellGet, which enables functionalities, such as the find, get, install, and uninstall packages from internal and public sources. However, this recipe is not specific to Exchange; see this recipe as a tips and tricks recipe, since it's more PowerShell general than Exchange-specific.

PowerShellGet is a package manager for Windows PowerShell. Basically, it is a wrapper around the OneGet component that simplifies the package management for PowerShell modules. PowerShellGet is built on top of the well-known package management solution NuGet.

OneGet is a unified package management component that allows you to search for software installation, uninstallation, and inventory for any type of software that it supports through its provider interface.

OneGet works with the community-based software repository called Chocolatey. Currently, Chocolatey has over 2,600 unique packages.

There are a bunch of galleries (also referred to as providers) to use and select from, such as PowerShell Resource Gallery (Microsoft supported), MyGet, Inedo ProGet, JFrog Artifactory, and many more.

For a better understanding, let's take a look at the first example.

How to do it...

In this example, we will use OneGet to install two example modules from Chocolatey:

Import-Module –Name OneGet
Get-Command –Module OneGet
Find-Package | Out-GridView
Find-Package –Name "notepadplusplus"
Find-Package –Name "7zip"
Install-Package –Name "7zip"
Install-Package –Name "notepadplusplus"–Force
Get-Package

How it works...

For illustrating how OneGet works we have seen the preceding example.

First, we imported the module of OneGet to use the cmdlets for the package manager. We then used the Get-Command cmdlet to see what commands are available with this module.

With the Find-Package cmdlet, we searched for available packages. First, we piped the results to a GridView, since this can be user friendly to watch instead of text. Once we find the packages we are looking for; in this example, Notepad++ and 7zip, we will use the Install-Package cmdlet to install these packages. The following screenshot shows you when the installation had taken place, the packages that are now available for use and can be found at the start button:

How it works...

Once the packages are in place, and we have verified that everything has worked as expected, we can finalize this by uninstalling them. The following are some examples of cmdlets used to uninstall packages:

Uninstall-Package –Name "notepadplusplus"
Uninstall-Package –Name "7zip"

There's more…

Chocolatey is great in many ways, but most companies or at least enterprise companies probably want to have their own internal, more trusted, and reliable repository but still hosted on the Internet.

So, 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 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 got an URL as 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. 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, you need to include the values of Author and Description, but I want to recommend that you also include the values of RootModule, ModuleVersion, and CompanyName. 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 we end 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

See also

  • Understanding the new execution policy
  • Creating custom objects
  • Working with Desired State Configuration
Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Microsoft Exchange Server Powershell Cookbook (Update)
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon