Coding Stephan

Introducing Content Prep PowerShell

Journey until now, I created WingetIntune on GitHub, an open-source app packager that downloads all the details from Winget and then packages the installer for Intune. In that last post I dove intune decrypting .intunewin files. With the end goal of being able to create those files with pure C# code. And I’m happy to announce that I succeeded in doing so.

Super fast Content Prep

A library and a PowerShell module

Now that I figured out how to decrypt .intunewin files, I created a library that can create those files with the same inputs as the official tool. And I created a PowerShell module that uses this new library to create .intunewin files. The PowerShell module is a drop-in replacement for the current Content Prep Tool, but it’s faster and cross-platform.

I set the following requirements for myself:

  • ✅ The library must be able to create intunewin files, and decrypt them.
  • ✅ The library must target .NETSTANDARD2.0 to be compatible with both .NET Framework and .NET Core.
  • ✅ The library must be fast, and use asynchronous IO to be able to handle large files, and to be able to use this inside ASP.NET Core (which blocks synchronous IO).
  • ❌ The library must support all the features of the current Content Prep Tool.

Apparently the current Content Prep tool, has (at least) two features that I could not implemented in the library:

  1. Extracting information from the MSI file, like the ProductCode, UpgradeCode, and ProductVersion.
  2. Using a catalog file.

For the first feature I could not find a cross platform solution, and for the second feature I could not find any documentation on how to use it. So I decided to not implement those features, let me know if you have any ideas on how to implement those features.

The PowerShell module

The PowerShell module is a drop-in replacement for the current Content Prep Tool, but it’s faster and cross-platform. It’s available on the PowerShell Gallery and can be installed using the following command:

Install-Module -Name SvRooij.ContentPrep.Cmdlet -Scope CurrentUser

Create a new intunewin file

New-IntuneWinPackage -SourcePath "C:\Path\To\Source" -SetupFile "C:\Path\To\Source\setup.exe" -DestinationPath "C:\Path\To\Destination" 

Super fast Content Prep

Creating an .intunewin file for the Microsoft.EdgeWebView2Runtime installer (which is 135mb) it takes roughly 5.8 seconds on my machine. The official Content Prep Tool takes 9 seconds on the same machine with the same setup. So it’s almost 2 times faster.

Decrypt an intunewin file

Off course you can also decrypt an intunewin file, using the following command:

Unlock-IntuneWinPackage -SourceFile C:\tools\packages\...\file.intunewin -DestinationPath C:\some\output\path

Decrypting and extracting the previously created .intunewin file takes about 1 second on my machine. Which is super fast if you ask me.

Decrypting an intunewin file in 1 second

The library

The library is available on NuGet, and can be installed using the following command:

dotnet add package SvRooij.ContentPrep --version 0.1.3-alpha0001

Mind you this is all still in alpha, so things might change in the future.

Since the PowerShell module is just a wrapper around this library, you can expect the same performance from the library as from the PowerShell module. It might even be slightly better since the PowerShell module has to do some extra work to make it work in PowerShell.

You said it was open-source?

I know I said it was open-source, but I haven’t published the source code yet. I’m still working on it, and I want to make sure it’s all working before I publish it. You can find the source code of the library and the PowerShell module on GitHub.

I’ll also be publishing a blog post with an in-depth explanation on creating intunewin files, like I did for the decrypting part. So stay tuned for that.

Series: Intune

Conclusion

Building this library was a lot of fun, and I learned a lot about the internals of the intunewin files. By wrapping my library in a PowerShell module, I was able to create a drop-in replacement for the current Content Prep Tool, which it both faster and cross-platform. Off course the decryption is not in the original tool, but that was my way in to this whole thing.

With both the library and the PowerShell module, I hope everybody can start creating Intunewin files on whatever platform they desire. I’m super happy with the results, and I’m looking forward to publishing the source code.

If you reached this point you’re in for a treat, the latest alpha version of WingetIntune 0.6.0-alpha0012 it the first version which is actually cross platform. Try it out and let me know what you think.

I hope you enjoyed this post, and if you have any feedback, please let me know on Twitter or LinkedIn.