Last active
April 21, 2022 05:39
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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