protected override void ProcessRecord()
        {
            if (ListProfile.IsPresent)
            {
                WriteWarning("The ListProfile switch is deprecated and will be removed from a future release.  Please use ListProfileDetail instead.");
                WriteObject(SettingsStore.GetProfileInfo(ProfileLocation).Select(pi => pi.ProfileName), true);
                return;
            }
            else if (ListProfileDetail.IsPresent)
            {
                WriteObject(SettingsStore.GetProfileInfo(ProfileLocation), true);
                return;
            }

            if (string.IsNullOrEmpty(ProfileName))
            {
                var creds = this.SessionState.PSVariable.Get(SessionKeys.AWSCredentialsVariableName);
                if (creds != null && creds.Value != null && creds.Value is AWSPSCredentials)
                {
                    WriteObject((creds.Value as AWSPSCredentials).Credentials);
                }
            }
            else
            {
                CredentialProfile profile;
                if (SettingsStore.TryGetProfile(ProfileName, ProfileLocation, out profile))
                {
                    WriteObject(profile.GetAWSCredentials(profile.CredentialProfileStore));
                }
            }
        }
        protected override void ProcessRecord()
        {
            if (SettingsStore.ProfileExists(ProfileName, ProfileLocation))
            {
                if (!ConfirmShouldProceed(Force.IsPresent, ProfileName, "Remove-AWSCredentialProfile"))
                {
                    return;
                }

                // clear credentials from credentials store
                SettingsStore.UnregisterProfile(ProfileName, ProfileLocation);

                // find profiles with the same name in .NET and default shared files
                var leftoverProfiles = SettingsStore.GetProfileInfo(null).Where(pi => string.Equals(pi.ProfileName, ProfileName, StringComparison.Ordinal));

                // issue warnings for those profiles
                foreach (var profileProperties in leftoverProfiles)
                {
                    if (string.Equals(profileProperties.StoreTypeName, typeof(SharedCredentialsFile).Name, StringComparison.Ordinal))
                    {
                        WriteWarning("Remove succeeded, but there is still a profile named '" + ProfileName + "' in the shared credentials file at " +
                                     profileProperties.ProfileLocation + ".");
                    }
                    else if (string.Equals(profileProperties.StoreTypeName, typeof(NetSDKCredentialsFile).Name, StringComparison.Ordinal))
                    {
                        WriteWarning("Remove succeeded, but there is still a profile named '" + ProfileName + "' in the .NET credentials file.");
                    }
                }
            }
            else
            {
                ThrowTerminatingError(new ErrorRecord(new ArgumentException("The CredentialProfile '" + ProfileName + "' does not exist."),
                                                      "ArgumentException", ErrorCategory.InvalidArgument, this));
            }
        }
        private AWSPSCredentials PromptUserForCredentials()
        {
            var storedCredentials = SettingsStore.GetProfileInfo(ProfileLocation);

            if (storedCredentials.Any())
            {
                // If there are stored credentials, ask user which ones to use, or enter new ones
                var choices = new Collection <ChoiceDescription>();
                choices.Add(new ChoiceDescription("<Create new credentials set>"));
                foreach (var profileInfo in storedCredentials)
                {
                    // help message cannot be null
                    var helpMessage = profileInfo.ProfileLocation == null ? profileInfo.StoreTypeName : profileInfo.ProfileLocation;
                    choices.Add(new ChoiceDescription(profileInfo.ProfileName, helpMessage));
                }

                var choice = Host.UI.PromptForChoice("Saved credentials found", CredentialsPrompt, choices, 0);
                if (choice != 0)
                {
                    var            chosenCredentials = choices[choice];
                    AWSCredentials awsCredentials;
                    if (SettingsStore.TryGetAWSCredentials(chosenCredentials.Label, ProfileLocation, out awsCredentials))
                    {
                        return(new AWSPSCredentials(awsCredentials, chosenCredentials.Label, CredentialsSource.Profile));
                    }
                }
            }

            var descriptions = new Collection <FieldDescription>();

            descriptions.Add(new FieldDescription(AccessKeyFieldName));
            descriptions.Add(new FieldDescription(SecretKeyFieldName));
            var response = Host.UI.Prompt("Credentials", "Please enter your AWS Access and Secret Keys", descriptions);

            var accessKey = response[AccessKeyFieldName].BaseObject as string;
            var secretKey = response[SecretKeyFieldName].BaseObject as string;

            if (string.IsNullOrEmpty(accessKey))
            {
                throw new ArgumentOutOfRangeException(AccessKeyFieldName + " is not set");
            }
            if (string.IsNullOrEmpty(secretKey))
            {
                throw new ArgumentOutOfRangeException(SecretKeyFieldName + " is not set");
            }

            var credentials = new BasicAWSCredentials(accessKey, secretKey);

            // this set will be saved as our default name
            return(new AWSPSCredentials(credentials, SettingsStore.PSDefaultSettingName, CredentialsSource.Profile));
        }