コード例 #1
0
        public PSADServicePrincipal GetServicePrincipalByObjectId(string objectId)
        {
            PSADServicePrincipal servicePrincipal = null;

            try
            {
                servicePrincipal = GraphClient.ServicePrincipals.Get(objectId).ToPSADServicePrincipal();
            }
            catch { /* The service principal does not exist, ignore the exception. */ }

            return(servicePrincipal);
        }
コード例 #2
0
        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);
                }
            });
        }
コード例 #3
0
        public PSADServicePrincipal GetServicePrincipalBySPN(string spn)
        {
            PSADServicePrincipal servicePrincipal = null;

            try
            {
                var odataQuery = new Rest.Azure.OData.ODataQuery <ServicePrincipal>(s => s.ServicePrincipalNames.Contains(spn));
                servicePrincipal = GraphClient.ServicePrincipals.List(odataQuery.ToString()).First().ToPSADServicePrincipal();
            }
            catch { /* The service principal does not exist, ignore the exception. */ }

            return(servicePrincipal);
        }
コード例 #4
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);
                }
            });
        }
コード例 #7
0
        public PSADServicePrincipal RemoveServicePrincipal(string objectId)
        {
            var objectIdString = objectId.ToString();
            PSADServicePrincipal servicePrincipal = FilterServicePrincipals(new ADObjectFilterOptions()
            {
                Id = objectId
            }).FirstOrDefault();

            if (servicePrincipal != null)
            {
                GraphClient.ServicePrincipals.Delete(objectIdString);
            }
            else
            {
                throw new KeyNotFoundException(string.Format(ProjectResources.ServicePrincipalDoesntExist, objectId));
            }

            return(servicePrincipal);
        }