Created
July 29, 2019 20:40
-
-
Save ImIOImI/471303498fb22ae1bf5a4198998ddc1a to your computer and use it in GitHub Desktop.
Simple Powershell script for switching a named profile into the default profile
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
Param( | |
[Parameter(Mandatory = $false)][string]$profile = "" | |
) | |
if ($profile -eq "") | |
{ | |
$profile = Read-Host -Prompt "What profile should we switch to?" | |
} | |
Write-Host "Using profile $profile" -ForegroundColor Green | |
$keys = @( | |
'output' | |
'region' | |
'aws_access_key_id' | |
'aws_secret_access_key' | |
) | |
foreach ($key in $keys) | |
{ | |
$getCmd = "aws configure get $profile.$key" | |
try | |
{ | |
$value = Invoke-Expression $getCmd | |
if (($lastexitcode) -and ($key -ne 'output') -and ($key -ne 'region')) | |
{ | |
throw $er | |
} | |
} | |
catch | |
{ | |
Write-Host "Value doesn't exist for $profile.$key, exiting..." -ForegroundColor Red | |
break | |
} | |
if ($value) | |
{ | |
$setCmd = "aws configure set default.$key $value" | |
Invoke-Expression $setCmd | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment