6

I've found one module really instresting, and want to use it on whole AD domain. Is there any way, to automatize this process? In normal Powershell, I have to simply call this command, with admin privileges:

Install-Module -Name $moduleName

And if it's untrusted repository, then I have to change it:

Set-PSRepository -name $repoName -InstallationPolicy trusted

I'm looking for more elegant way, than runing these commands on computer startup, as simple PS script.

The ideal solution would look like this:

  1. Something checks, if computer has installed modules on it.
  2. If it doesn't, then modules are installed, and computer is from now recognised as machine with modules installed.
  3. If it does have modules installed, then no actions are taken.

Or even better:

  1. There is some sort of container, that contains computers without installed modules.
  2. Modules are installed on every computer in this container, and then moved outside of it.

The second one could work on simple domain containers, where we got subcontainer with GPO, that runs PS script with commands from above. We can move computers through this structure, by using PS Active Directory cmdlets. And I see next problem, would automatic moving from container to another container, be safe on a bigger scale and in longer period of time?

  • I guess I'm confused. Are you trying to make the module available to all the users on all the computers? If you want to use the module when you create remote sessions to those computers, you can do that as long as the one you're remoting from has the module. If the remote computers all need the module installed, why not write a script to install it on all of them. Oh, and -confirm:$false answers no to confirmation prompts, it doesn't disable the prompts. – Xalorous Aug 31 '16 at 16:59
  • @Xalorous as i said in question, I can make script, that would install modules on computers, but it's not elegant solution, because if I want to be sure, that all the computers have modules installed, this installator script would have to be run frequently, not only in case, where it's needed. About confirmation, you are right, I will correct that. Also look on my "pseudo solution" example, that I added. – PatrykMilewski Aug 31 '16 at 18:50
  • 1
    Have your script check if the module is there if(get-module targetmodulename) { <#do nothing#> } else { <# code to install module #> }. Have the script run as a machine startup script. – Xalorous Aug 31 '16 at 21:46
  • @Xalorous So if this script will run as a machine startup script, then it will be executed, even when there is no need of execution. That's not the best solution, I already mentioned this before. – PatrykMilewski Sep 1 '16 at 9:34
  • If the machine doesn't need the module, the only thing that's executed is the check. The load is on the local machine, and it's miniscule. – Xalorous Sep 1 '16 at 14:10
2

You have to make a to steps job.

1)Create an msi that install your module, simple way is explain here

2)Use a GPO to install the MSI to all machines, as explain here

  • Thank you! That's exactly the way, I was looking for! I won't test it, because situation already changed, and I don't need extern modules in my AD, but I hope, that your soultion works fine. I marked this as answer, because idea of making modules into msi packages is great. – PatrykMilewski Sep 8 '16 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.