2025-11-28 00:35:46 +09:00
..
new
2025-11-28 00:35:46 +09:00
new
2025-11-28 00:35:46 +09:00

Windows PowerShell Script Line Profiler Sample

This sample shows how to create a script line profiler using the new Windows PowerShell 3.0 AST (Abstract Syntax Tree) support.

The sample defines the InstrumentAst class (derived from the ICustomAstVisitor interface) that builds an AST object. The AST object inserts a Profile object callback that measures the execution time of each script statement. The profiler can be run on script files using the provided Measure-Script cmdlet.

Sample Objectives

  1. Creating a script line profiler using Windows PowerShell
  2. AST support.
  3. Running the provided Measure-Script cmdlet to profile a script file.

Windows PowerShell

ICustomAstVisitor

Operating system requirements

Client

Windows 8.1

Server

Windows Server 2012 R2

Build the sample

  1. Start Microsoft Visual Studio and select File > Open > Project/Solution.

  2. Go to the directory named for the sample, and double-click the Visual Studio Solution (.sln) file.

  3. Make sure the PSProfiler project references the System.Management.Automation.dll assembly.

  4. Press F7 or use Build > Build Solution to build the sample.

    The executable will be built in the default \bin or \bin\Debug directory.

Run the sample

  1. Run Import-Module with the full path to the sample DLL.
  2. Run the Measure-Script cmdlet on a script file.