Installing Modules for Powershell Core (pwsh)
What is Powershell Core (pwsh) ?
Powershell Core is a cross-platform version of Powershell.
It is meant to run on Linux, Windows and MacOs
- More info here: Powershell Core Docs
Install Powershell Core (pwsh)
Here will we run Powershell Core in a Docker Container readily available by Microsoft.
mcr.microsoft.com/powershell:lts-nanoserver-1809 is a docker image readily available on Microsoft's Docker Hub which already has Powershell Core installed.
We will be using this image as a base container image in a Dockerfile later on.
Browse Powershell Core Modules
Next you can head over to the Powershell Gallery to find which Powershell Moduels are available for download.
Here we will be installing the DnsClient-PS module to resolve DNS names.
Install a Module
Here we have created a Dockerfile with a list of commands to both use the mcr.microsoft.com/powershell:lts-nanoserver-1809 container image and install the DnsClient-PS module.
To build the docker image, simply run:
# Use a readily available powershell core docker image by Microsoft as base
FROM mcr.microsoft.com/powershell:lts-nanoserver-1809
# Run as admin
USER ContainerAdministrator
# Make default shell powershell
SHELL ["pwsh", "-command"]
# Label powershell gallery as trusted
RUN Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
# Add ContainerAdministrator's powershell module location to PSModulePath
RUN setx /M PSModulePath $($env:PSModulePath + 'C:\Users\ContainerAdministrator\Documents\PowerShell\Modules')
# Install powershell core dns module DnsClient-PS
RUN Install-Module -Name DnsClient-PS -SkipPublisherCheck -RequiredVersion 1.0.0
# Run a simple command on startup
ENTRYPOINT [ "Resolve-DNS", "www.microsoft.com" ]
Furthermore, to run Powershell Core interactively inside the Docker container itself, run:
Wow! You read this far? Feel free to get in touch on my secret contact page !