Skip to main content

Get started

⚠️ IMPORTANT This module is early in it´s development phase. Many API function and features are not yet available. You are welcome to contribute on GitHub to accelerate progress further.

PSPortainer

This project has adopted the following policies CodeOfConduct Contributing Security

Project status

GitHub Workflow Status Codecov Platform PowerShell Gallery License docs changelog GitHub release (latest SemVer including pre-releases) GitHub release (latest SemVer including pre-releases)

About

PSPortainer is a wrapper for the Portainer Rest API. This module is work-in-progress and new functions and features are released frequently.

Installation

To install from the PowerShell gallery using PowerShellGet run the following command:

Install-Module PSPortainer -Scope CurrentUser

Usage

Connect to Portainer

To interact with portainer we first need to connect to our Portainer instance. We do not maintain a session with portainer by definition but we do store the portainer URL and authentication information as well as testing and verifying that we successfully can communicate with the Portainer API. We can use several methods of authentication. (As of writing this two methods is currently supported but the aim is support all available authentication schemes). We can use an AccessToken that is generated by the user in the Portainer web UI or we can connect using username/password.

AccessToken

Connect-Portainer -BaseURL 'https://portainer.contoso.com' -AccessToken 'ptr_ABoR54bB1NUc4aNY0F2PhppP1tVDu2Husr3vEbPUsw5='

Credentials

Connect-Portainer -BaseURL 'https://portainer.contoso.com' -Credentials (Get-Credential)

Call functions

Once a session is establish you start using the cmdlets provided with the module. For instance list all docker containers;

Get-PContainer

To get a single container by ID use

Get-PContainer -Id '<id>'

Connect to multiple Portainer instances from the same Powershell Session

It is possible to work with two Portainer instances within the same powershell session by storing the session information in variables and then provide the session object to each cmdlet.

$Instance1 = Connect-Portainer -BaseURL 'https://portainer-01.contoso.com' -AccessToken 'ptr_ABoR54bB1NUc4aNY0F2PhppP1tVDu2Husr3vEbPUsw5=' -PassThru
$Instance2 = Connect-Portainer -BaseURL 'https://portainer-02.contoso.com' -AccessToken 'ptr_ABoR54bB1NUc4aNY0F2PhppP1tVDu2Husr3vEbPUsw5=' -PassThru

Get-PContainer -Session $Instance1
Get-PContainer -Session $Instance2

Do note that the last Connect-Portainer call will be the fallback session that is used if the cmdlet is not provided with a session object. In the example above, a call to Get-PContainer without a -Session parameter would use the instance portainer-02.