Skip to content

Instantly share code, notes, and snippets.

@ImIOImI
Created July 29, 2019 20:40
Show Gist options
  • Save ImIOImI/471303498fb22ae1bf5a4198998ddc1a to your computer and use it in GitHub Desktop.
Save ImIOImI/471303498fb22ae1bf5a4198998ddc1a to your computer and use it in GitHub Desktop.
Simple Powershell script for switching a named profile into the default profile
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