Quick script to automatically updated my AWS access ID and secret

#setup
#set-psrepository psgallery -installationpolicy Trusted
#install-module AWSPowerShell.NetCore -scope currentuser -AllowClobber -force
import-module AWSPowerShell.NetCore
$profilename = 'ohyeah'
# Initialize-AWSDefaultConfiguration -region us-west-2 -AccessKey $x -SecretKey $y
Initialize-AWSDefaultConfiguration -ProfileName $profilename
$keys = get-iamaccesskey
if(($keys | measure-object).count -gt 1) { "Two keys already exist, must delete one first" | out-host}
elseif(($keys|measure-object).count -eq1)
{
    "One key exists, ready to switch" | out-host
    $newkey=new-iamaccesskey
    Set-AWSCredential -AccessKey $newkey.AccessKeyId -SecretKey $newkey.SecretAccessKey -StoreAs $profilename
    Initialize-AWSDefaultConfiguration -profileName $profilename
    Remove-IAMAccessKey -AccessKeyId $keys.AccessKeyId -passthru -force # old key
}