Skip to content

Instantly share code, notes, and snippets.

@austoonz
Last active April 21, 2022 05:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save austoonz/b7bc0bad0a522671dfa9716b7bf2099c to your computer and use it in GitHub Desktop.
Save austoonz/b7bc0bad0a522671dfa9716b7bf2099c to your computer and use it in GitHub Desktop.
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 {
[CmdletBinding()]
param (
[ValidateScript({Test-Path -Path $_ -PathType Leaf})]
$FilePath
)
$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