public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                PSADServicePrincipal servicePrincipal = null;
                if (this.IsParameterBound(c => c.InputObject))
                {
                    ObjectId = InputObject.Id;
                }

                if (!this.IsParameterBound(c => c.ObjectId) && ObjectId != Guid.Empty)
                {
                    IEnumerable <PSADServicePrincipal> result = null;
                    if (this.IsParameterBound(c => c.ApplicationId) || this.IsParameterBound(c => c.ApplicationObject))
                    {
                        var appId = ApplicationObject == null ? ApplicationId.ToString() : ApplicationObject.ApplicationId.ToString();
                        Rest.Azure.OData.ODataQuery <ServicePrincipal> odataQuery = new Rest.Azure.OData.ODataQuery <ServicePrincipal>(s => s.AppId == appId);
                        result = ActiveDirectoryClient.FilterServicePrincipals(odataQuery);
                    }
                    else if (this.IsParameterBound(c => c.ServicePrincipalName) || this.IsParameterBound(c => c.DisplayName))
                    {
                        ADObjectFilterOptions options = new ADObjectFilterOptions()
                        {
                            SPN          = ServicePrincipalName,
                            SearchString = DisplayName
                        };

                        result = ActiveDirectoryClient.FilterServicePrincipals(options);
                    }

                    if (result == null)
                    {
                        throw new ArgumentException(string.Format("Could not find a service principal with the name {0}.", ServicePrincipalName));
                    }

                    ObjectId = result.Select(s => s.Id).FirstOrDefault();
                }


                ConfirmAction(
                    Force.IsPresent,
                    string.Format(ProjectResources.RemovingServicePrincipal, ObjectId),
                    ProjectResources.RemoveServicePrincipal,
                    ObjectId.ToString(),
                    () => servicePrincipal = ActiveDirectoryClient.RemoveServicePrincipal(ObjectId));

                if (PassThru)
                {
                    WriteObject(servicePrincipal);
                }
            });
        }
Ejemplo n.º 2
0
        public override void ExecuteCmdlet()
        {
            PSADServicePrincipal servicePrincipal = null;

            ConfirmAction(
                ProjectResources.RemoveServicePrincipal,
                null,
                () => servicePrincipal = ActiveDirectoryClient.RemoveServicePrincipal(ObjectId.ToString()));

            if (PassThru)
            {
                WriteObject(servicePrincipal);
            }
        }
        protected override void ProcessRecord()
        {
            PSADServicePrincipal servicePrincipal = null;

            ConfirmAction(
                Force.IsPresent,
                string.Format(ProjectResources.RemovingServicePrincipal, ObjectId),
                ProjectResources.RemoveServicePrincipal,
                null,
                () => servicePrincipal = ActiveDirectoryClient.RemoveServicePrincipal(ObjectId.ToString()));

            if (PassThru)
            {
                WriteObject(servicePrincipal);
            }
        }
        public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                PSADServicePrincipal servicePrincipal = null;

                ConfirmAction(
                    Force.IsPresent,
                    string.Format(ProjectResources.RemovingServicePrincipal, ObjectId.ToString()),
                    ProjectResources.RemoveServicePrincipal,
                    ObjectId.ToString(),
                    () => servicePrincipal = ActiveDirectoryClient.RemoveServicePrincipal(ObjectId.ToString()));

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