Пример #1
0
        public override void ExecuteCmdlet()
        {
            switch (ParameterSetName)
            {
            case RemoveVaultParameterSet:
                ResourceGroupName = string.IsNullOrWhiteSpace(ResourceGroupName) ? GetResourceGroupName(VaultName) : ResourceGroupName;
                if (string.IsNullOrWhiteSpace(ResourceGroupName))
                {
                    throw new ArgumentException(string.Format(PSKeyVaultProperties.Resources.VaultNotFound, VaultName, ResourceGroupName));
                }
                ConfirmAction(
                    Force.IsPresent,
                    string.Format(
                        CultureInfo.InvariantCulture,
                        PSKeyVaultProperties.Resources.RemoveVaultWarning,
                        VaultName),
                    string.Format(
                        CultureInfo.InvariantCulture,
                        PSKeyVaultProperties.Resources.RemoveVaultWhatIfMessage,
                        VaultName),
                    VaultName,
                    () =>
                {
                    KeyVaultManagementClient.DeleteVault(
                        vaultName: VaultName,
                        resourceGroupName: this.ResourceGroupName);
                });
                break;

            case RemoveDeletedVaultParameterSet:
                ConfirmAction(
                    Force.IsPresent,
                    string.Format(
                        CultureInfo.InvariantCulture,
                        PSKeyVaultProperties.Resources.PurgeVaultWarning,
                        VaultName),
                    string.Format(
                        CultureInfo.InvariantCulture,
                        PSKeyVaultProperties.Resources.PurgeVaultWhatIfMessage,
                        VaultName),
                    VaultName,
                    () =>
                {
                    KeyVaultManagementClient.PurgeVault(
                        vaultName: VaultName,
                        location: Location);
                });
                break;

            default:
                throw new ArgumentException(PSKeyVaultProperties.Resources.BadParameterSetName);
            }
        }
        public override void ExecuteCmdlet()
        {
            if (InputObject != null)
            {
                VaultName         = InputObject.VaultName;
                ResourceGroupName = InputObject.ResourceGroupName;
                Location          = InputObject.Location;
            }

            if (InRemovedState)
            {
                ConfirmAction(
                    Force.IsPresent,
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.PurgeVaultWarning,
                        VaultName),
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.PurgeVaultWhatIfMessage,
                        VaultName),
                    VaultName,
                    () =>
                {
                    KeyVaultManagementClient.PurgeVault(
                        vaultName: VaultName,
                        location: Location);

                    if (PassThru)
                    {
                        WriteObject(true);
                    }
                });
            }
            else
            {
                ResourceGroupName = string.IsNullOrWhiteSpace(ResourceGroupName) ? GetResourceGroupName(VaultName) : ResourceGroupName;
                if (string.IsNullOrWhiteSpace(ResourceGroupName))
                {
                    throw new ArgumentException(string.Format(Resources.VaultNotFound, VaultName, ResourceGroupName));
                }
                ConfirmAction(
                    Force.IsPresent,
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.RemoveVaultWarning,
                        VaultName),
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.RemoveVaultWhatIfMessage,
                        VaultName),
                    VaultName,
                    () =>
                {
                    KeyVaultManagementClient.DeleteVault(
                        vaultName: VaultName,
                        resourceGroupName: this.ResourceGroupName);

                    if (PassThru)
                    {
                        WriteObject(true);
                    }
                });
            }
        }