kine / NVRAppDevOps

Navertica DevOps scripts for managing Microsoft Dynamics 365 Business Central Apps
31 stars 29 forks source link

Use Invoke-ScriptInNavContainer cmdlet. #15

Closed ernestasju closed 5 years ago

ernestasju commented 5 years ago

Hi @kine,

I am using navcontainerhelper\Check-NavContainerHelperPermissions -Fix to use containers without requiring administrator permissions.

Currently Init-ALEnvironment and some other cmdlets are using navcontainerhelper\Get-NavContainerSession to return PowerShell session and then Invoke-Command cmdlet to invoke commands.

The problem is that Get-NavContainerSession cannot find running container when not running as administrator. You get error like this:

PS C:\Users\ernjus\Desktop\TMP-ExternalDocumentNo> docker ps
CONTAINER ID        IMAGE                                                   COMMAND                  CREATED             STATUS                    PORTS                                                NAMES
d70e2173a074        mcr.microsoft.com/businesscentral/sandbox:lt-ltsc2019   "powershell -Command…"   11 minutes ago      Up 11 minutes (healthy)   80/tcp, 443/tcp, 1433/tcp, 7045-7049/tcp, 8080/tcp   BCEDN
PS C:\Users\ernjus\Desktop\TMP-ExternalDocumentNo> Get-NavContainerSession -containerName BCEDN
New-PSSession : The input ContainerId d70e2173a0742457ff4609ef932fbf6ebc66fb78ecaf8766d4f2fb1d81a8f4fd does not exist, or the corresponding container is not running.
At C:\Users\ernjus\Documents\WindowsPowerShell\Modules\navcontainerhelper\0.6.0.8\ContainerHandling\Get-NavContainerSession.ps1:37 char:24
+ ...  $session = New-PSSession -ContainerId $containerId -RunAsAdministrat ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-PSSession], PSInvalidOperationException
    + FullyQualifiedErrorId : CreateRemoteRunspaceForContainerFailed,Microsoft.PowerShell.Commands.NewPSSessionCommand

Thanks.

kine commented 5 years ago

Thanks Ernestas for your contribution!

Merged.

kine commented 5 years ago

Published in v0.9.59

ernestasju commented 5 years ago

Nice. :)