ps/Modules/Cole.PowerShell.Developer/Public/Get-LocalConfiguredAWSProfileNames.ps1
2023-05-30 22:51:22 -07:00

29 lines
756 B
PowerShell

function Get-LocalConfiguredAWSProfileNames {
<#
.SYNOPSIS
Get the locally configured AWS Profile Names for the current user
#>
[CmdletBinding()]
[OutputType([string[]])]
param (
$CredentialsFilePath = '~/.aws/credentials'
)
$logLead = (Get-LogLeadName)
if (!(Test-Path $CredentialsFilePath)) {
throw "$logLead : Can't find your credentials file at [$CredentialsFilePath]. Do you need to configure one? You can run [Register-AWSCredentials]."
}
$lines = (Get-Content -Path $CredentialsFilePath)
$profileNames = @()
foreach($line in $lines) {
if ($line -match "\[[\w-]+\]") {
$profileNames += $line.Substring(1,$line.Length - 2)
}
}
return $profileNames
}