29 lines
756 B
PowerShell
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
|
|
} |