How to use modules and package providers during OSD with MECM (SCCM/MEMCM)

Jake ShackelfordPowershell, ScriptingLeave a Comment

For the past few days, I’ve been implementing SnipeIT into our environment to start actually tracking assets as opposed to the archaic spreadsheet we had going. I wanted to add any new machine that were imaged into the database right away without any input from me. That way, all I had to do was assign a user to the device in the asset management portal for SnipeIT, and I was good to go. However, this proved to be quite the headache for me. Special thanks to Christopher Kibble, Colin Wilkins, and Adam Gross for all their support and helping me learn some PS along the way (I’m still a noob).

It’s easier than it sounds!

I’ve used many PowerShell scripts during OSD In the past and thanks to the recent changes, where you can just paste a script into a task sequence, it’s become even easier! With this in mind, I created a script and tested it on my dev machine and a few others, and everything looked great. They ran in the SYSTEM context fine, as an admin fine, all looked dandy. I put it into my OSD, and it returned successful but never actually showed up into my asset management system. After trying everything under the sun including placement of the script during OSD, turning it into an application, making it a package, etc. I just could not get it to work during OSD. I was about ready to give in but was thinking maybe it’s an issue with installing the modules and package providers (It was).

How to get those lovely modules and packages during OSD.

In my use case, I already had the module and package provider I needed installed to my machine.

You can find the modules you need at $env:ProgramFiles\WindowsPowerShell\Modules assuming you have them installed on your machine.

You can find PackageProviders at $env:ProgramFiles\PackageManagement\ProviderAssemblies also assuming you have them installed on your machine.

I copied the WindowsPowerShell folder and the PacakageManagement folders to a new folder on my SCCM server

In my case, my folder structure for the entire package looks like so:


Once we have these two folders in a folder on our SCCM, we can create a package.

Now please forgive me for my terrible PS skills I’m working on improving them!

Create a script in the same folder you put PackageManegemet and WindowsPowerShell that looks like the following

$executingScriptDirectory = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent

copy-item $executingScriptDirectory\PackageManagement $env:ProgramFiles -force -Recurse

copy-item $executingScriptDirectory\WindowsPowershell $env:ProgramFiles -force -Recurse

In my case, I called this script MoveItems.ps1

Once you have this complete create a package with all the content.

In your OSD task Sequence create a run PowerShell script step and reference the package you made like so


Next, in your original script that’s failing to run, you’ll want to IMPORT those modules or packageproviders as opposed to installing them since you now have the content copied to that local machine. In my case the code looks like so: (This will look different depending on the modules you are trying to import)

Import-Module -Name $env:ProgramFiles\WindowsPowerShell\Modules\SnipeitPS -Verbose

Import-PackageProvider -Name "Nuget" -Verbose

Add another Run PowerShell script to your task sequence and reference your script with the newly added Import commands and you should be good to go! Don’t forget to update your distribution point for the package you created!

If anyone is interested in the actual SnipeIT script feel free to come to the WinAdmins discord and send me a message!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.