1

I am trying to run a simple powershell script from a docker container. The script is supposed to create an AD group. The problem I am facing is that the ActiveDirectory module is not available, which is why commands such as "New-ADGroup" are not recognized.

This is my DockerFile

FROM packages.company.ch/icbuild/powershell
WORKDIR /app
COPY ./rabbitmq-adgroups-deploy/1.0/ /app
RUN pwsh -c "Get-PSRepository"
CMD [ "pwsh", "rabbitmq-adgroups.ps1"]

And this is my script "rabbitmq-adgroups.ps1"

  Register-PSRepository -Default
  Get-PSRepository
  Install-Module ActiveDirectory
  ....
  New-ADGroup -Name $SecurityGroup
  ....

And these are the log messages I get

  • When building the docker image, the moment it runs the "RUN pwsh -c "Get-PSRepository" command

WARNING: Unable to find module repositories.

  • When executing the powershell script, commands "Get-PSRepository", "Install-Module ..." and "New-ADGroup ..." respectively

WARNING: Unable to find module repositories.

Install-Package: No match was found for the specified search criteria and module name 'ActiveDirectory'. Try Get-PSRepository to see all available registered module repositories.

The term 'Add-ADGroupMember' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

  • A few suggestion here but I guess you already followed these https://stackoverflow.com/questions/43323123/warning-unable-to-find-module-repositories – Nick.Mc Jun 20 '22 at 10:36

1 Answers1

0

I found out that it is not possible to run a powershell script that requires the Active Directory module from a Linux based Docker image, which is what I was doing.... At the end I decided to simply run the script from a Windows Machine without any Docker image whatsoever....