Behind the PowerShell Pipeline logo

Behind the PowerShell Pipeline

Archives
Log in
Subscribe
September 11, 2026

PowerShell Tool Of The Month

In this issue:

  • Parsing with the AST
  • Help Document
  • Get-ASTScriptProfile
  • Summary

I thought I'd introduce something new into the mix on a monthly basis. I have a huge library of PowerShell tools, many of which I use myself. I've written about many of them in past newsletters over the years. At a minimum, you've seen me use these tools from the PSScriptTools module:

  • New-PSFormatXML
  • Get-TypeMember
  • Get-ParameterInfo

And of course the tools I've been created using the pwshSpectreConsole module like Show-SpecreSystemStatus

Once a month I want to share something new. At least I think it will be new to you. Today's tool is something I wrote years ago but I have cleaned it up a bit. I try to document my code liberally with comments so I won't spend a lot of time detailing the code.

> All of my code is offered as-is with no guarantees, warranties, or support. You should review and test everything in a non-production environment.

Parsing with the AST

Today's tool is an extension of past articles I've written on using the Abstract Syntax Tree (AST) in PowerShell. You can use the AST to parse a script file or script block and discover the individual elements that make it tick.

If you need a refresher, take a look at these items from the archives:

  • Going Out on a Limb on the Abstract Syntax Tree
  • Climbing Higher in the Abstract Syntax Tree
  • Creating AST-Based PowerShell Tools
  • PowerShell Parsing and Processing
  • Positioning with the PowerShell AST

Years ago in the PowerShell v2 days, the original Scripting Guy, Ed Wilson, asked me to write a PowerShell script that would dissect a file and prepare a report showing what commands were going to be called, if any of the commands might be potentially dangerous like Remove-Item and anything else that an IT Pro might want to know about a script. This was before the PowerShell Gallery when we often downloaded scripts from blogs and web sites. Ed's idea was to have a tool that would create a profile of the script that would provide useful information for someone who may not have extensive PowerShell experience.

A lot of this work was done with simple string parsing and regular expressions. Then PowerShell v3.0 introduced the AST. Over time, I revised the script profiling tool to use the AST. This allowed me to discover other information about how a script is constructed. Today, I want to share the current version of this tool with you.

Help Document

The earlier versions of my profiling tool wrote a text based report to the console that you could save to a file. At some point, I made the decision to create an about help topic file with script profile information.

an about script profile
figure 1 - an about script profile

Here's a fun side-effect of creating a file like this. By default, my profiling script saves the file to your TEMP folder. You would use Get-Content to look at the file or open in Notepad or VSCode. However you can specify a different folder. If you create a folder that is part of a location in $env:PSModulePath, you can use the help system to find and view the file.

I created C:\Users\Jeff\Documents\WindowsPowerShell\Modules\ScriptProfiles. The directory will be treated as a module which means it will be searched. I can save my profile reports to this directory.

Get-ASTProfile -Path C:\scripts\Set-ADPassword.ps1 -FilePath c:\users\jeff\documents\windowsPowerShell\Modules\ScriptProfiles

The file name format is about_<script-name>. If I know what I'm looking for, I can display it using help.

PS C:\&gt; help about_Set-ADPassword
TOPIC
about Set-ADPassword.ps1 script profile

SHORT DESCRIPTION
Script Profile report for: C:\scripts\Set-ADPassword.ps1
Created: 09/11/2026 12:25:23

LONG DESCRIPTION
This is an analysis of a PowerShell script or module. Analysis will most likely NOT be 100% thorough.

REQUIREMENTS
RequiredApplicationId :
RequiredPSVersion     : 4.0
RequiredPSEditions    : {}
RequiredModules       : {ActiveDirectory}
RequiredAssemblies    : {}
IsElevationRequired   : False
...

> The Created date is the date of the profile not the script.

However, each about topic also includes a keyword, scriptProfile. This isn't necessarily fast, but it should work.

help scriptprofile
figure 2 - help scriptprofile

Once I know the name, I can use the help command to display it.

Here's a complete sample.

TOPIC
about WeatherTicker.psm1 script profile

SHORT DESCRIPTION
Script Profile report for: C:\scripts\WeatherTicker.psm1
Created: 09/11/2026 11:24:17

LONG DESCRIPTION
This is an analysis of a PowerShell script or module. Analysis will most likely NOT be 100% thorough.

REQUIREMENTS
    - None detected

PARAMETERS
    - None detected. Parameters for nested commands are not tested.

FUNCTIONS DEFINED
    - Get-YahooWeather
    - Start-WeatherTitleTicker

ALL COMMANDS
All possible PowerShell commands for v5.1.26100.9278. This list may not be complete or even correct.

CommandType Name                 Version Source
----------- ----                 ------- ------
Cmdlet      Export-ModuleMember  3.0.0.0 Microsoft.PowerShell.Core
Cmdlet      Get-Command          3.0.0.0 Microsoft.PowerShell.Core
Cmdlet      Get-Date             3.1.0.0 Microsoft.PowerShell.Utility
Cmdlet      Get-Unique           3.1.0.0 Microsoft.PowerShell.Utility
Cmdlet      New-Object           3.1.0.0 Microsoft.PowerShell.Utility
Cmdlet      Out-Null             3.0.0.0 Microsoft.PowerShell.Core
Cmdlet      Receive-Job          3.0.0.0 Microsoft.PowerShell.Core
Cmdlet      Register-ObjectEvent 3.1.0.0 Microsoft.PowerShell.Utility
Cmdlet      Set-Alias            3.1.0.0 Microsoft.PowerShell.Utility
Cmdlet      Sort-Object          3.1.0.0 Microsoft.PowerShell.Utility
Cmdlet      Start-Job            3.0.0.0 Microsoft.PowerShell.Core
Cmdlet      Start-Sleep          3.1.0.0 Microsoft.PowerShell.Utility
Cmdlet      Write-Output         3.1.0.0 Microsoft.PowerShell.Utility
Cmdlet      Write-Verbose        3.1.0.0 Microsoft.PowerShell.Utility
Cmdlet      Write-Warning        3.1.0.0 Microsoft.PowerShell.Utility

UNRESOLVED
These commands may be called from nested commands or unknown modules.

Get-YahooWeather


TYPENAMES
These are identified .NET type names that might be used as accelerators.

[char]
[console]
[datetime]
[scriptblock]
[string]
[xml]

WARNING
These are potentially dangerous commands.

    - None detected

ERRORS
    - None detected

KEYWORDS
    - scriptProfile

Does this look like something you would use?

Get-ASTScriptProfile

Want to read the full issue?
Already a paid subscriber? Click here to log in.
GitHub
Bluesky
LinkedIn
Mastodon
jdhitsolutions.github.io
Powered by Buttondown, the easiest way to start and grow your newsletter.