Skip to content

Instantly share code, notes, and snippets.

Last active April 21, 2022 05:39
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
This function will use the PowerShell Parser, and the Get-AWSCmdletName cmdlet (found in AWS.Tools.Common, AWSPowerShell or AWSPowerShell.NetCore) to find and output all AWS Cmdlets from a script. This can be used to assist with migrations to the modular AWS Tools for PowerShell.
function Get-AWSCommandsFromFile {
param (
[ValidateScript({Test-Path -Path $_ -PathType Leaf})]
$awsCommands = @{}
$tokens = [System.Management.Automation.PSParser]::Tokenize((Get-Content -Path $FilePath -Raw), [ref]$null)
foreach ($token in $tokens) {
if ($token.Type -ne 'Command') { continue }
$awsCmdlet = Get-AWSCmdletName -CmdletName $token.Content
if ($awsCmdlet) {
$key = '{0}{1}' -f $awsCmdlet.ModuleName, $awsCmdlet.CmdletName
if ($awsCommands.ContainsKey($key)) { continue }
$null = $awsCommands.Add($key, $awsCmdlet)
$awsCommands.Values | Sort-Object -Property ModuleName, CmdletName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment