Example #1
0
        protected override void ProcessRecord()
        {
            CertificateBundle certBundle;

            switch (ParameterSetName)
            {
            case ByCertificateNameParameterSet:
                certBundle = this.DataServiceClient.GetCertificate(VaultName, Name, Version ?? string.Empty);
                var certificate = KeyVaultCertificate.FromCertificateBundle(certBundle);
                this.WriteObject(certificate);
                break;

            case ByCertificateVersionsParameterSet:
                certBundle = this.DataServiceClient.GetCertificate(VaultName, Name, string.Empty);
                if (certBundle != null)
                {
                    WriteObject(new CertificateIdentityItem(certBundle));
                    GetAndWriteCertificatesVersions(VaultName, Name, certBundle.CertificateIdentifier.Version);
                }
                break;

            case ByVaultNameParameterSet:
                GetAndWriteCertificates(VaultName);
                break;

            case ByDeletedCertificateParameterSet:
                if (Name == null)
                {
                    GetAndWriteDeletedCertificates(VaultName);
                    break;
                }

                DeletedKeyVaultCertificate deletedCert = DeletedKeyVaultCertificate.FromDeletedCertificateBundle(DataServiceClient.GetDeletedCertificate(VaultName, Name));
                WriteObject(deletedCert);

                break;

            default:
                throw new ArgumentException(KeyVaultProperties.Resources.BadParameterSetName);
            }
        }
        protected override void ProcessRecord()
        {
            if (InRemovedState.IsPresent)
            {
                ConfirmAction(
                    Force.IsPresent,
                    string.Format(
                        CultureInfo.InvariantCulture,
                        KeyVaultProperties.Resources.RemoveDeletedCertificateWarning,
                        Name),
                    string.Format(
                        CultureInfo.InvariantCulture,
                        KeyVaultProperties.Resources.RemoveDeletedCertificateWhatIfMessage,
                        Name),
                    Name,
                    () => { DataServiceClient.PurgeCertificate(VaultName, Name); });

                return;
            }

            DeletedKeyVaultCertificate certBundle = null;

            ConfirmAction(
                Force.IsPresent,
                string.Format(
                    CultureInfo.InvariantCulture,
                    KeyVaultProperties.Resources.RemoveCertWarning,
                    Name),
                string.Format(
                    CultureInfo.InvariantCulture,
                    KeyVaultProperties.Resources.RemoveCertWhatIfMessage,
                    Name),
                Name,
                () => { certBundle = DeletedKeyVaultCertificate.FromDeletedCertificateBundle(this.DataServiceClient.DeleteCertificate(VaultName, Name)); });

            if (PassThru.IsPresent)
            {
                WriteObject(certBundle);
            }
        }