public/Container/Start-PContainer.ps1
<#PSScriptInfo
{ "VERSION": "1.0.0", "GUID": "97a4ab27-c8c2-4715-aa10-3cf73e2b5eea", "FILENAME": "Start-PContainer.ps1", "AUTHOR": "Hannes Palmquist", "CREATEDDATE": "2022-10-28", "COMPANYNAME": [], "COPYRIGHT": "(c) 2022, Hannes Palmquist, All Rights Reserved" } PSScriptInfo#> function Start-PContainer { <# .DESCRIPTION Starts a container .PARAMETER Endpoint Defines the portainer endpoint to use when retreiving containers. If not specified the portainer sessions default docker endpoint value is used. Use Get-PSession to see what endpoint is selected Use Select-PEndpoint to change the default docker endpoint in the portainer session. -Endpoint 'local' .PARAMETER Id Defines the id of the container to retreive. -Id '<Id>' .PARAMETER Session Optionally define a portainer session object to use. This is useful when you are connected to more than one portainer instance. -Session $Session .EXAMPLE Start-PContainer Description of example #> [CmdletBinding(SupportsShouldProcess)] param( [Parameter()][string]$Endpoint, [Parameter(ValueFromPipeline)][object[]]$Id, [Parameter()][PortainerSession]$Session = $null ) BEGIN { $Session = Get-PSession -Session:$Session $EndpointID = ResolveEndpointID -Endpoint:$Endpoint -Session:$Session } PROCESS { $Id | ForEach-Object { if ($PSItem.PSObject.TypeNames -contains 'PortainerContainer') { $ContainerID = $PSItem.Id } elseif ($PSItem.GetType().Name -eq 'string') { $ContainerID = $PSItem } else { Write-Error -Message 'Cannot determine input object type' -ErrorAction Stop } if ($PSCmdlet.ShouldProcess($ContainerID, 'Start')) { try { InvokePortainerRestMethod -Method POST -RelativePath "/endpoints/$EndpointId/docker/containers/$ContainerID/start" -PortainerSession:$Session } catch { if ($_.Exception.Message -like '*304 (Not Modified)*') { Write-Warning -Message "Container <$ContainerID> is already started" } elseif ($_.Exception.Message -like '*404*') { Write-Error -Message "No container with id <$ContainerID> could be found" } else { Write-Error -Message "Failed to start container with id <$ContainerID> with error: $_" } } } } } } #endregion # SIG # Begin signature block # MIIbmAYJKoZIhvcNAQcCoIIbiTCCG4UCAQExCzAJBgUrDgMCGgUAMGkG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