Place the .csproj in the same folder as MeasureScriptBlockMemoryCommand.cs (assuming folder is src in this example):
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>library</OutputType>
<AssemblyName>MeasureScriptBlockMemoryCommand</AssemblyName>
<TargetFramework>net10.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="10.0.7" />
<PackageReference Include="System.Management.Automation" Version="7.6.1" PrivateAssets="all" />
</ItemGroup>
</Project>Compile it using the dotnet CLI, you need .NET SDK 10+:
PS ..\pwsh> cd .\src
PS ..\src> dotnet publish --configuration Release -o .\lib
PS ..\pwsh> Import-Module .\src\lib\MeasureScriptBlockMemoryCommand.dll
PS ..\pwsh> Measure-ScriptBlockMemory { Get-ChildItem C:\ -Depth 4 -EA 0 } | FT
TimeStamp Span InvocationMemoryInMb ProcessMemoryInMb Invocation
--------- ---- -------------------- ----------------- ----------
5/4/2026 11:29:48 AM 00:00:00.0042701 0.00 158.92 Get-ChildItem C:\ -Depth 4 -EA 0
5/4/2026 11:29:48 AM 00:00:00.5092726 2.67 161.59 Get-ChildItem C:\ -Depth 4 -EA 0
5/4/2026 11:29:49 AM 00:00:01.0192534 14.51 173.43 Get-ChildItem C:\ -Depth 4 -EA 0
5/4/2026 11:29:49 AM 00:00:01.5590699 88.12 247.04 Get-ChildItem C:\ -Depth 4 -EA 0
5/4/2026 11:29:50 AM 00:00:02.0711037 198.14 357.06 Get-ChildItem C:\ -Depth 4 -EA 0
5/4/2026 11:29:50 AM 00:00:02.5808020 241.89 400.81 Get-ChildItem C:\ -Depth 4 -EA 0
5/4/2026 11:29:51 AM 00:00:03.0914375 308.49 467.41 Get-ChildItem C:\ -Depth 4 -EA 0
5/4/2026 11:29:51 AM 00:00:03.6022986 338.77 497.69 Get-ChildItem C:\ -Depth 4 -EA 0
5/4/2026 11:29:52 AM 00:00:04.1183466 348.41 507.33 Get-ChildItem C:\ -Depth 4 -EA 0
5/4/2026 11:29:52 AM 00:00:04.6334695 355.06 513.98 Get-ChildItem C:\ -Depth 4 -EA 0
5/4/2026 11:29:53 AM 00:00:05.1504214 369.18 528.09 Get-ChildItem C:\ -Depth 4 -EA 0
5/4/2026 11:29:53 AM 00:00:05.6611558 376.88 535.80 Get-ChildItem C:\ -Depth 4 -EA 0
5/4/2026 11:29:54 AM 00:00:06.1735121 387.57 546.48 Get-ChildItem C:\ -Depth 4 -EA 0
5/4/2026 11:29:54 AM 00:00:06.6855683 403.80 562.72 Get-ChildItem C:\ -Depth 4 -EA 0
5/4/2026 11:29:55 AM 00:00:07.1983418 414.84 573.75 Get-ChildItem C:\ -Depth 4 -EA 0
5/4/2026 11:29:55 AM 00:00:07.7126693 426.56 585.48 Get-ChildItem C:\ -Depth 4 -EA 0
5/4/2026 11:29:56 AM 00:00:08.2267385 435.40 594.32 Get-ChildItem C:\ -Depth 4 -EA 0
5/4/2026 11:29:56 AM 00:00:08.7506555 444.45 603.37 Get-ChildItem C:\ -Depth 4 -EA 0
5/4/2026 11:29:57 AM 00:00:09.2676887 466.34 625.25 Get-ChildItem C:\ -Depth 4 -EA 0
5/4/2026 11:29:57 AM 00:00:09.7787815 473.64 632.56 Get-ChildItem C:\ -Depth 4 -EA 0
5/4/2026 11:29:58 AM 00:00:10.2898625 522.69 681.61 Get-ChildItem C:\ -Depth 4 -EA 0
5/4/2026 11:29:59 AM 00:00:10.7998353 535.00 693.91 Get-ChildItem C:\ -Depth 4 -EA 0
5/4/2026 11:29:59 AM 00:00:11.3124713 541.42 700.34 Get-ChildItem C:\ -Depth 4 -EA 0
5/4/2026 11:30:00 AM 00:00:11.8262417 555.22 714.14 Get-ChildItem C:\ -Depth 4 -EA 0
5/4/2026 11:30:00 AM 00:00:12.3388784 565.68 724.60 Get-ChildItem C:\ -Depth 4 -EA 0
5/4/2026 11:30:01 AM 00:00:12.8507531 581.93 740.85 Get-ChildItem C:\ -Depth 4 -EA 0