Created
August 9, 2023 22:14
-
-
Save Echooff3/737bb402cd5419b743d186efebc5c5bd to your computer and use it in GitHub Desktop.
Update AWS Creds from Powershell
This file contains hidden or 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
# Make sure you have a creds object in your clipboard | |
function creds () { | |
Import-Module "Microsoft.PowerShell.Management" | |
Import-Module "PsIni" # Make sure you have this installed | |
$pth = "~\.aws\credentials" # Update to your path | |
$creds = Get-IniContent $pth | |
$cb = Get-Clipboard | |
try { | |
$first, $rest = $cb | |
$section = "default" | |
$final = @($section, $rest[0], $rest[1], $rest[2]) | |
$final2 = @($rest[0], $rest[1], $rest[2]) | |
$creds[$section]["aws_access_key_id"] = $rest[0] | |
$creds[$section]["aws_secret_access_key"] = $rest[1] | |
$creds[$section]["aws_session_token"] = $rest[2] | |
Out-IniFile -FilePath $pth -InputObject $creds -Force | |
} | |
catch { "Check your clipboard" } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment