r/PowerShell • u/splatteredbits • Jul 27 '26
News PureInvoke 2.0.0 Released
We've released PureInvoke 2.0.0!
We package and ship our code with their PowerShell module dependencies in the package. This way, we don't have to install our modules globally on all the servers we deploy our code to. This requires us to make extensive use of nested dependencies. We've gotten to the point that our dependencies are starting to use different versions of PureInvoke. Unfortunately, because it was using compiled assemblies, and .NET will only load assemblies with the same name once, we started to run into problems.
This release changes PureInvoke's compilation model. Instead of pre-compiling platform-specific assemblies, the module now uses Add-Type to compile P/Invoke C# code at runtime. This should improve cross-platform and cross-edition support. Since we've encountered problems with Add-Type in environments with aggressive anti-virus, PureInvoke re-tries failed compilations to improve resiliency.
We also added functions for querying Windows service configurations, e.g. Invoke-AdvApiQueryServiceConfig which wraps QueryServiceConfigW, Invoke-AdvApiQueryServiceConfig2, which wraps QueryServiceConfig2W, etc.:
Full release notes on GitHub.
26
u/psrobin Jul 28 '26
Hi. There are probably thousands of PowerShell affectionados reading this subreddit without any clue what this post is about. Provide more context please, if you're going to advertise a new release of something.
6
u/MonkeyNin Jul 29 '26
It looks like you are dotsourcing all functions, every import. That can also trigger a false positive on AVG.
You can build your functions into one file when you go to publish it. If you want the dotsourcing for local development.
3
u/cloudAhead Jul 28 '26
Most people who have the problems that this solves would likely just use C#. But, thank you for sharing with the community.
16
u/pdpelsem Jul 28 '26
What's the for?
11
u/mbrulzagain Jul 28 '26
From the git
The PureInvoke module contains functions that handles the complexity of using P/Invoke to call Win32 APIs.
There is no native way to call Win32 APIs in PowerShell. In order to use P/Invoke, you have to compile C# code into an assembly, or use PowerShell's Add-Type cmdlet to compile it dynamically at runtime. But then you have to worry about converting all the native handles and pointer to and from .NET objects.
The PureInvoke solves this by wrapping Win32 APIs with PowerShell functions that take and return .NET objects and does all the work of converting to and from .NET and Win32 APIs.