Powershell/Private/Add-NativeMethod.ps1
function Add-NativeMethod { [CmdletBinding()] [Alias()] [OutputType([int])] Param($typeName = 'NativeMethods') process { $nativeMethodsCode = $script:nativeMethods | ForEach-Object { " [DllImport(`"$($_.Dll)`")] public static extern $($_.Signature); " } Add-Type @" using System; using System.Text; using System.Runtime.InteropServices; public static class $typeName { $nativeMethodsCode } "@ } } |