What is best practice around PackageManagement module?

Hello,

I’m confused about what I’m supposed to do with built in PackageManagement module which comes preinstalled with Windows 2016. I can not update it directly since it was not installed from Gallery and when I install newer version from Gallery I end up with 2 modules and 2 names for all DSC Resources. How do I uninstall built in module or what is best practice here?

Yeah, unfortunately due to the way protected system files exist, they can’t be updated that way (although you can try using -Force). The most you can do is try to delete them, although in many cases the system will attempt to “repair” itself and put them back. It’s something I don’t think they thought through really well.

This actually comes up with Pester a lot (see https://github.com/pester/Pester/issues/488 as well as https://github.com/pester/Pester/issues/585); it might be useful to look at what other folks have donee and see what works for you.

How do I properly refer to latest version of PackageManagement module in such cases when using Import-Module or Import-DSCResource

You can target a version using -RequiredVersion parameter for Import-module cmdlet. There are more ways to control version for this cmdlet. I suggest you to take a look at the help documentation of Import-Module cdmlet.

for Import-DSCResource, below usage can be done.

Import-DscResource -ModuleName @{ModuleName='yourModule';ModuleVersion=”1.0″}

I need to load latest version of module. Notation inside Import-DSCresource requires exact module version. Script I’m working on will be used on computers for quite sometime and I want always the latest version of PackageManagement resources to be used. I assume there is no solution to this?

Latest version will be picked by default.