public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                if (!string.IsNullOrEmpty(ServicePrincipalName))
                {
                    ObjectId = ActiveDirectoryClient.GetObjectIdFromSPN(ServicePrincipalName);
                }

                bool deleteAllCredentials = false;
                if (All.IsPresent)
                {
                    deleteAllCredentials = true;
                }

                if (KeyId != Guid.Empty)
                {
                    ConfirmAction(
                        Force.IsPresent,
                        string.Format(ProjectResources.RemovingSpCredentialWithId, KeyId, ObjectId),
                        ProjectResources.RemoveCredential,
                        ObjectId,
                        () => ActiveDirectoryClient.RemoveSpCredentialByKeyId(ObjectId, KeyId));
                }
                else if (deleteAllCredentials)
                {
                    ConfirmAction(
                        Force.IsPresent,
                        string.Format(ProjectResources.RemovingAllSpCredentials, ObjectId),
                        ProjectResources.RemoveCredential,
                        ObjectId,
                        () => ActiveDirectoryClient.RemoveAllSpCredentials(ObjectId));
                }
            });
        }
示例#2
0
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                if (this.IsParameterBound(c => c.ServicePrincipalObject))
                {
                    ObjectId = ServicePrincipalObject.Id;
                }
                else if (this.IsParameterBound(c => c.ServicePrincipalName))
                {
                    ObjectId = ActiveDirectoryClient.GetObjectIdFromSPN(ServicePrincipalName);
                }
                else if (this.IsParameterBound(c => c.DisplayName))
                {
                    ObjectId = ActiveDirectoryClient.GetObjectIdFromServicePrincipalDisplayName(DisplayName);
                }

                if (this.IsParameterBound(c => c.KeyId))
                {
                    ConfirmAction(
                        Force.IsPresent,
                        string.Format(ProjectResources.RemovingSpCredentialWithId, KeyId, ObjectId),
                        ProjectResources.RemoveCredential,
                        ObjectId.ToString(),
                        () => ActiveDirectoryClient.RemoveSpCredentialByKeyId(ObjectId, KeyId));
                }
                else
                {
                    ConfirmAction(
                        Force.IsPresent,
                        string.Format(ProjectResources.RemovingAllSpCredentials, ObjectId),
                        ProjectResources.RemoveCredential,
                        ObjectId.ToString(),
                        () => ActiveDirectoryClient.RemoveAllSpCredentials(ObjectId));
                }

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