Home > Mobile >  Could not Load dbatools in Linux Container
Could not Load dbatools in Linux Container

Time:11-15

I'm installing dbatools to run on a Ubuntu Container.

Error:

 Could not import /usr/local/share/powershell/Modules/dbatools/1.1.142/bin/smo/coreclr/System.Security.SecureString.dll : Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'System.Security.SecureString, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'."
 At /usr/local/share/powershell/Modules/dbatools/1.1.142/internal/scripts/libraryimport.ps1:150 char:21
                       [Reflection.Assembly]::LoadFrom($assemblyPath)
                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
   FullyQualifiedErrorId : FileLoadException
  
 Import-Module : The specified module '/usr/local/share/powershell/Modules/dbatools/1.1.142/bin/dbatools.dll' was not loaded because no valid module file was found in any module directory.
 At /Test5.ps1:12 char:1
   Import-Module dbatools
   ~~~~~~~~~~~~~~~~~~~~~~
   CategoryInfo          : ResourceUnavailable: (/usr/local/share/po\u202642/bin/dbatools.dll:String) [Import-Module], FileNotFoundException
   FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

My Dockerfile

From myImage

RUN pwsh -Command 'Set-PSRepository -Name PSGallery -InstallationPolicy Trusted'

RUN pwsh -command "Install-Module sqlserver -Scope AllUsers -Force"
RUN pwsh -command "Install-Module dbatools -Scope AllUsers -Force"
RUN pwsh -command "Get-module -ListAvailable -Name 'dbatools'"
RUN pwsh -command "Get-module -ListAvailable -Name 'sqlserver'"

COPY Test5.ps1 .

CMD [ "pwsh", "Test5.ps1"]

myImage contains the requred setup to run powershell on ubuntu 20.

Test5.ps1

Import-Module dbatools

What do I need to do to make my powershell module work without needing to be manually imported?

THANKS!

CodePudding user response:

dbatools raise this as an issue and to be fix on 2.0.

  • Related