public NeoQueryData CollectData()
        {
            NeoQueryData  querydata    = new NeoQueryData();
            List <object> propertylist = new List <object>();

            try
            {
                // This query selects all collections
                int type = (int)PackageType.RegularSoftwareDistribution;

                string cmquery = "select * from SMS_PackageBaseclass WHERE PackageType='" + type + "'";

                // Run query
                using (IResultObject results = Connector.Instance.Connection.QueryProcessor.ExecuteQuery(cmquery))
                {
                    // Enumerate through the collection of objects returned by the query.
                    foreach (IResultObject resource in results)
                    {
                        propertylist.Add(new
                        {
                            Name        = ResultObjectHandler.GetString(resource, "Name"),
                            ID          = ResultObjectHandler.GetString(resource, "PackageID"),
                            Description = ResultObjectHandler.GetString(resource, "Description"),
                            PackageType = ((PackageType)ResultObjectHandler.GetInt(resource, "PackageType")).ToString()
                        });
                    }
                }
            }
            catch { }

            querydata.Properties = propertylist;
            return(querydata);
        }
Beispiel #2
0
        public NeoQueryData CollectData()
        {
            NeoQueryData  querydata    = new NeoQueryData();
            List <object> propertylist = new List <object>();

            try
            {
                // This query selects all collections
                string cmquery = "select * from SMS_Collection";

                // Run query
                using (IResultObject results = Connector.Instance.Connection.QueryProcessor.ExecuteQuery(cmquery))
                {
                    // Enumerate through the collection of objects returned by the query.
                    foreach (IResultObject resource in results)
                    {
                        int typeint = ResultObjectHandler.GetInt(resource, "CollectionType");

                        propertylist.Add(new
                        {
                            ID   = ResultObjectHandler.GetString(resource, "CollectionID"),
                            Name = ResultObjectHandler.GetString(resource, "Name"),
                            LimitingCollectionID = ResultObjectHandler.GetString(resource, "LimitToCollectionID"),
                            Comment = ResultObjectHandler.GetString(resource, "Comment"),
                            IncludeExcludeCollectionCount = ResultObjectHandler.GetInt(resource, "IncludeExcludeCollectionsCount"),
                            CollectionType = ((CollectionType)typeint).ToString()
                        });
                    }
                }
            }
            catch { }

            querydata.Properties = propertylist;
            return(querydata);
        }
Beispiel #3
0
        public NeoQueryData CollectData()
        {
            NeoQueryData  querydata    = new NeoQueryData();
            List <object> propertylist = new List <object>();

            try
            {
                // This query selects all collections
                string        cmquery = "select CollectionID,ResourceID from SMS_FullCollectionMembership";
                List <object> retlist = new List <object>();

                // Run query
                using (IResultObject results = Connector.Instance.Connection.QueryProcessor.ExecuteQuery(cmquery))
                {
                    // Enumerate through the collection of objects returned by the query.
                    foreach (IResultObject resource in results)
                    {
                        string colids     = ResultObjectHandler.GetString(resource, "CollectionID");
                        string resourceid = ResultObjectHandler.GetString(resource, "ResourceID");

                        //split the collection list and
                        foreach (string collectionid in colids.Split(','))
                        {
                            propertylist.Add(new { resourceid, collectionid });
                        }
                    }
                }
            }
            catch { }

            querydata.Properties = propertylist;
            return(querydata);
        }
        public NeoQueryData CollectData()
        {
            NeoQueryData  querydata    = new NeoQueryData();
            List <object> propertylist = new List <object>();

            try
            {
                // This query selects all collections
                string cmquery = "select * from SMS_CIRelation WHERE RelationType=6";

                // Run query
                using (IResultObject results = Connector.Instance.Connection.QueryProcessor.ExecuteQuery(cmquery))
                {
                    // Enumerate through the collection of objects returned by the query.
                    foreach (IResultObject resource in results)
                    {
                        propertylist.Add(new
                        {
                            FromCIID = ResultObjectHandler.GetString(resource, "FromCIID"),
                            ToCIID   = ResultObjectHandler.GetString(resource, "ToCIID")
                        });
                    }
                }
            }
            catch { }

            querydata.Properties = propertylist;
            return(querydata);
        }
        public NeoQueryData CollectData()
        {
            NeoQueryData querydata = new NeoQueryData();

            querydata.Properties = this._mappings;
            return(querydata);
        }
Beispiel #6
0
        public NeoQueryData CollectData()
        {
            NeoQueryData  querydata    = new NeoQueryData();
            List <object> propertylist = new List <object>();

            try
            {
                // This query selects all collections
                string cmquery = "select * from SMS_R_User";

                // Run query
                using (IResultObject results = Connector.Instance.Connection.QueryProcessor.ExecuteQuery(cmquery))
                {
                    // Enumerate through the collection of objects returned by the query.
                    foreach (IResultObject resource in results)
                    {
                        propertylist.Add(new
                        {
                            ID  = ResultObjectHandler.GetString(resource, "ResourceId"),
                            SID = ResultObjectHandler.GetString(resource, "SID"),
                            DN  = ResultObjectHandler.GetString(resource, "DistinguishedName"),
                            //dev.OU = ResultObjectHandler.GetString(resource, "SystemOUName"),
                            Name = ResultObjectHandler.GetString(resource, "Name"),
                            //dev.CollectionIDs.Add(resource["CollectionID"].StringValue)
                        });
                    }
                }
            }
            catch { }

            querydata.Properties = propertylist;
            return(querydata);
        }
        public NeoQueryData CollectData()
        {
            NeoQueryData  querydata    = new NeoQueryData();
            List <object> propertylist = new List <object>();

            try
            {
                // https://docs.microsoft.com/en-us/configmgr/develop/reference/osd/sms_tasksequenceappreferencesinfo-server-wmi-class
                string        cmquery = "select * from SMS_TaskSequenceAppReferencesInfo";
                List <object> retlist = new List <object>();

                // Run query
                using (IResultObject results = Connector.Instance.Connection.QueryProcessor.ExecuteQuery(cmquery))
                {
                    // Enumerate through the collection of objects returned by the query.
                    foreach (IResultObject resource in results)
                    {
                        string tsid  = ResultObjectHandler.GetString(resource, "PackageID");
                        string appid = ResultObjectHandler.GetString(resource, "RefAppCI_ID");
                        propertylist.Add(new { tsid, appid });
                    }
                }
            }
            catch { }

            querydata.Properties = propertylist;
            return(querydata);
        }
        public NeoQueryData CollectData()
        {
            NeoQueryData  querydata    = new NeoQueryData();
            List <object> propertylist = new List <object>();

            try
            {
                string cmquery = "select * from SMS_TaskSequencePackage";

                // Run query
                using (IResultObject results = Connector.Instance.Connection.QueryProcessor.ExecuteQuery(cmquery))
                {
                    // Enumerate through the collection of objects returned by the query.
                    foreach (IResultObject resource in results)
                    {
                        propertylist.Add(new
                        {
                            ID               = ResultObjectHandler.GetString(resource, "PackageID"),
                            Name             = ResultObjectHandler.GetString(resource, "Name"),
                            TaskSequenceType = ((TaskSequenceType)ResultObjectHandler.GetInt(resource, "Type")).ToString()
                        });
                    }
                }
            }
            catch { }

            querydata.Properties = propertylist;
            return(querydata);
        }
Beispiel #9
0
        public async Task <NeoQueryData> CollectDataAsync()
        {
            this.DriveIDs = new List <string>();

            NeoQueryData querydata = new NeoQueryData();

            querydata.Properties = new List <object>();

            //var test = Connector.Instance.Client.Sites["20road-my.sharepoint.com,0690831f-23fa-4515-86e9-c7805d152326,605f593f-0e0c-45dd-bfb4-dda5f2241b77"].Drives.Request().Top(999);
            //var test2 = await test.GetAsync();

            //requests.Add(Connector.Instance.Client.Drives.Request().Top(999));
            foreach (string id in AadGroups.Instance.O365GroupIDs)
            {
                var facade = FacadeGroupDrivesRequest.GetFacade(Connector.Instance.Client.Groups[id].Drives.Request().Top(999));
                querydata.Properties.AddRange(await ProcessRequestAsync(id, facade));
            }
            Console.Write(".");
            foreach (string id in AadSites.Instance.SiteIDs)
            {
                var facade = FacadeSitesDrivesRequest.GetFacade(Connector.Instance.Client.Sites[id].Drives.Request().Top(999));
                querydata.Properties.AddRange(await ProcessRequestAsync(id, facade));
            }
            Console.Write(".");
            foreach (string id in AadUsers.Instance.UserIDs)
            {
                var facade = FacadeUserDrivesRequest.GetFacade(Connector.Instance.Client.Users[id].Drives.Request().Top(999));
                querydata.Properties.AddRange(await ProcessRequestAsync(id, facade));
            }
            Console.Write(".");

            return(querydata);
        }
        public NeoQueryData CollectData()
        {
            NeoQueryData  querydata    = new NeoQueryData();
            List <object> propertylist = new List <object>();

            try
            {
                // This query selects all collections
                string cmquery = "select * from SMS_Application WHERE IsLatest='TRUE'";

                // Run query
                using (IResultObject results = Connector.Instance.Connection.QueryProcessor.ExecuteQuery(cmquery))
                {
                    // Enumerate through the collection of objects returned by the query.
                    foreach (IResultObject resource in results)
                    {
                        propertylist.Add(new
                        {
                            IsDeployed    = ResultObjectHandler.GetBool(resource, "IsDeployed"),
                            IsEnabled     = ResultObjectHandler.GetBool(resource, "IsEnabled"),
                            IsSuperseded  = ResultObjectHandler.GetBool(resource, "IsSuperseded"),
                            IsSuperseding = ResultObjectHandler.GetBool(resource, "IsSuperseding"),
                            IsLatest      = ResultObjectHandler.GetBool(resource, "IsLatest"),
                            ID            = ResultObjectHandler.GetString(resource, "CI_ID"),
                            Name          = ResultObjectHandler.GetString(resource, "LocalizedDisplayName")
                        });
                    }
                }
            }
            catch { }

            querydata.Properties = propertylist;
            return(querydata);
        }
Beispiel #11
0
        public NeoQueryData CollectData()
        {
            NeoQueryData  querydata    = new NeoQueryData();
            List <object> propertylist = new List <object>();

            querydata.Properties = propertylist;
            return(querydata);
        }
Beispiel #12
0
        public async Task <NeoQueryData> CollectDataAsync()
        {
            NeoQueryData  querydata    = new NeoQueryData();
            List <object> propertylist = new List <object>();

            try
            {
                IGraphServiceGroupsCollectionPage page = await Connector.Instance.Client.Groups.Request().GetAsync();

                while (page != null)
                {
                    foreach (Group group in page.CurrentPage)
                    {
                        string grouptype = group.SecurityEnabled.Value ? "Security" : "Distribution";
                        bool   dynamic   = false;

                        foreach (string type in group.GroupTypes)
                        {
                            switch (type)
                            {
                            case "DynamicMembership":
                                dynamic = true;
                                break;

                            case "Unified":
                                this.O365GroupIDs.Add(group.Id);
                                grouptype = "Microsoft365";
                                break;

                            default:
                                break;
                            }
                        }

                        propertylist.Add(new
                        {
                            ID          = group.Id,
                            Dynamic     = dynamic,
                            Name        = group.DisplayName,
                            Description = group.Description,
                            MailEnabled = group.MailEnabled,
                            Mail        = group.Mail,
                            Type        = grouptype,
                            OnPremSid   = group.OnPremisesSecurityIdentifier
                        });

                        this.GroupIDs.Add(group.Id);
                    }

                    page = await page.NextPageRequest?.GetAsync();
                }
            }
            catch { }

            querydata.Properties = propertylist;
            return(querydata);
        }
Beispiel #13
0
        public async Task <NeoQueryData> CollectDataAsync()
        {
            NeoQueryData querydata = await Task.Run(() =>
            {
                return(this.CollectData());
            });

            return(querydata);
        }
Beispiel #14
0
        public NeoQueryData CollectData()
        {
            NeoQueryData  querydata    = new NeoQueryData();
            List <object> propertylist = new List <object>();


            try
            {
                using (PrincipalSearcher principalSearcher = new PrincipalSearcher(new UserPrincipal(this._context)))
                {
                    try
                    {
                        DirectorySearcher searcher = principalSearcher.GetUnderlyingSearcher() as DirectorySearcher;
                        if (searcher != null)
                        {
                            searcher.Filter      = ("(&(objectCategory=foreignSecurityPrincipal))");
                            searcher.SearchScope = SearchScope.Subtree;
                            searcher.PropertiesToLoad.Add("cn");
                            searcher.PropertiesToLoad.Add("name");
                            searcher.PropertiesToLoad.Add("objectcategory");
                            searcher.PropertiesToLoad.Add("objectSid");
                            searcher.PropertiesToLoad.Add("distinguishedName");
                            searcher.PropertiesToLoad.Add("description");

                            searcher.PageSize = 1000;
                            SearchResultCollection results = searcher.FindAll();

                            foreach (SearchResult result in results)
                            {
                                propertylist.Add(new
                                {
                                    name        = ADSearchResultConverter.GetSinglestringValue(result, "Name"),
                                    dn          = ADSearchResultConverter.GetSinglestringValue(result, "distinguishedname"),
                                    description = ADSearchResultConverter.GetSinglestringValue(result, "Description"),
                                    id          = ADSearchResultConverter.GetSidAsString(result)
                                });
                            }
                        }
                        else
                        {
                            Program.ExitError("Error retrieving foreign security principals from AD", ErrorCodes.ForeignSecurityPrincipalCollectorSearcherNull);
                        }
                    }
                    catch (Exception e)
                    {
                        Program.ExitError(e, "Error retrieving foreign security principals from AD", ErrorCodes.ForeignSecurityPrincipalCollectorSearcherException);
                    }
                }
            }
            catch { }

            querydata.Properties = propertylist;
            return(querydata);
        }
Beispiel #15
0
        public async Task <NeoQueryData> CollectDataAsync()
        {
            this.SiteIDs = new List <string>();
            NeoQueryData  querydata    = new NeoQueryData();
            List <object> propertylist = new List <object>();

            IGraphServiceSitesCollectionRequest request = Connector.Instance.Client.Sites.Request();

            request.Top(999);

            IGraphServiceSitesCollectionPage page = null;

            await Connector.Instance.MakeGraphClientRequestAsync(async() =>
            {
                page = await request.GetAsync();
            });

            while (page != null)
            {
                foreach (Site site in page.CurrentPage)
                {
                    this.SiteIDs.Add(site.Id); //record the site ID so it can be used later
                    string sitename = string.IsNullOrEmpty(site.DisplayName) ? site.Name : site.DisplayName;
                    sitename = string.IsNullOrEmpty(sitename) ? site.WebUrl : sitename;

                    propertylist.Add(new
                    {
                        ID          = site.Id,
                        WebUrl      = site.WebUrl,
                        DisplayName = site.DisplayName,
                        Name        = sitename,
                        SiteName    = site.Name,
                        Description = site.Description
                    });
                }

                if (page.NextPageRequest == null)
                {
                    break;
                }

                await Connector.Instance.MakeGraphClientRequestAsync(async() =>
                {
                    page = await page.NextPageRequest.GetAsync();
                });
            }

            querydata.Properties = propertylist;
            return(querydata);
        }
Beispiel #16
0
        public async Task <NeoQueryData> CollectDataAsync()
        {
            this.UserIDs = new List <string>();
            NeoQueryData  querydata    = new NeoQueryData();
            List <object> propertylist = new List <object>();

            IGraphServiceUsersCollectionRequest request = Connector.Instance.Client.Users.Request();

            request.Top(999);

            IGraphServiceUsersCollectionPage page = null;

            await Connector.Instance.MakeGraphClientRequestAsync(async() =>
            {
                page = await request.GetAsync();
            });

            while (page != null)
            {
                foreach (User user in page.CurrentPage)
                {
                    this.UserIDs.Add(user.Id);

                    propertylist.Add(new
                    {
                        ID      = user.Id,
                        Enabled = user.AccountEnabled,
                        UPN     = user.UserPrincipalName,
                        Name    = user.DisplayName
                    });
                }

                if (page.NextPageRequest == null)
                {
                    break;
                }

                await Connector.Instance.MakeGraphClientRequestAsync(async() =>
                {
                    page = await page.NextPageRequest.GetAsync();
                });
            }

            querydata.Properties = propertylist;
            return(querydata);
        }
        public NeoQueryData CollectData()
        {
            NeoQueryData  querydata    = new NeoQueryData();
            List <object> propertylist = new List <object>();

            try
            {
                // This query selects all collections
                string cmquery = "select * from SMS_SoftwareUpdate";

                // Run query
                using (IResultObject results = Connector.Instance.Connection.QueryProcessor.ExecuteQuery(cmquery))
                {
                    // Enumerate through the collection of objects returned by the query.
                    foreach (IResultObject resource in results)
                    {
                        propertylist.Add(new
                        {
                            ID               = ResultObjectHandler.GetString(resource, "CI_ID"),
                            ArticleID        = ResultObjectHandler.GetString(resource, "ArticleID"),
                            BulletinID       = ResultObjectHandler.GetString(resource, "BulletinID"),
                            DateCreated      = ResultObjectHandler.GetDateTime(resource, "DateCreated").ToString(),
                            DateRevised      = ResultObjectHandler.GetDateTime(resource, "DateRevised").ToString(),
                            Name             = ResultObjectHandler.GetString(resource, "LocalizedDisplayName"),
                            IsBundle         = ResultObjectHandler.GetBool(resource, "IsBundle"),
                            IsDeployed       = ResultObjectHandler.GetBool(resource, "IsDeployed"),
                            IsExpired        = ResultObjectHandler.GetBool(resource, "IsExpired"),
                            IsLatest         = ResultObjectHandler.GetBool(resource, "IsLatest"),
                            IsSuperseded     = ResultObjectHandler.GetBool(resource, "IsSuperseded"),
                            Description      = ResultObjectHandler.GetString(resource, "LocalizedDescription"),
                            NumMissing       = ResultObjectHandler.GetInt(resource, "NumMissing"),
                            PercentCompliant = ResultObjectHandler.GetInt(resource, "PercentCompliant"),
                            SeverityName     = ResultObjectHandler.GetString(resource, "SeverityName"),
                            Size             = ResultObjectHandler.GetInt(resource, "Size")
                        });
                    }
                }
            }
            catch { }

            querydata.Properties = propertylist;
            return(querydata);
        }
Beispiel #18
0
        public async Task <NeoQueryData> CollectDataAsync()
        {
            NeoQueryData  querydata    = new NeoQueryData();
            List <object> propertylist = new List <object>();

            IGraphServiceTeamsCollectionRequest request = Connector.Instance.Client.Teams.Request();

            request.Top(999);

            IGraphServiceTeamsCollectionPage page = null;

            await Connector.Instance.MakeGraphClientRequestAsync(async() =>
            {
                page = await request.GetAsync();
            });

            while (page != null)
            {
                foreach (Team team in page.CurrentPage)
                {
                    propertylist.Add(new
                    {
                        ID          = team.Id,
                        Description = team.Description,
                        IsArchived  = team.IsArchived,
                        Name        = team.DisplayName
                    });
                }

                if (page.NextPageRequest == null)
                {
                    break;
                }

                await Connector.Instance.MakeGraphClientRequestAsync(async() =>
                {
                    page = await page.NextPageRequest.GetAsync();
                });
            }

            querydata.Properties = propertylist;
            return(querydata);
        }
Beispiel #19
0
        public NeoQueryData CollectData()
        {
            NeoQueryData  querydata    = new NeoQueryData();
            List <object> propertylist = new List <object>();

            try
            {
                // This query selects all collections
                string cmquery = "select * from SMS_AuthorizationList";

                // Run query
                using (IResultObject results = Connector.Instance.Connection.QueryProcessor.ExecuteQuery(cmquery))
                {
                    // Enumerate through the collection of objects returned by the query.
                    foreach (IResultObject resource in results)
                    {
                        //https://docs.microsoft.com/en-us/configmgr/develop/core/understand/how-to-read-lazy-properties-by-using-managed-code
                        resource.Get();
                        int[]         lazyupdates = resource["Updates"].IntegerArrayValue;
                        List <string> updates     = new List <string>();

                        foreach (int i in lazyupdates)
                        {
                            updates.Add(i.ToString());
                        }

                        propertylist.Add(new
                        {
                            id          = ResultObjectHandler.GetString(resource, "CI_ID"),
                            name        = ResultObjectHandler.GetString(resource, "LocalizedDisplayName"),
                            description = ResultObjectHandler.GetString(resource, "LocalizedDescription"),
                            updates     = updates
                        });
                    }
                }
            }
            catch { }

            querydata.Properties = propertylist;
            return(querydata);
        }
        public NeoQueryData CollectData()
        {
            NeoQueryData  querydata    = new NeoQueryData();
            List <object> propertylist = new List <object>();

            try
            {
                // This query selects all collections
                string cmquery = "select * from SMS_Program";

                // Run query
                using (IResultObject results = Connector.Instance.Connection.QueryProcessor.ExecuteQuery(cmquery))
                {
                    // Enumerate through the collection of objects returned by the query.
                    foreach (IResultObject resource in results)
                    {
                        string programName = ResultObjectHandler.GetString(resource, "ProgramName");
                        string packageID   = ResultObjectHandler.GetString(resource, "PackageID");

                        propertylist.Add(new
                        {
                            ProgramName      = ResultObjectHandler.GetString(resource, "ProgramName"),
                            DependentProgram = ResultObjectHandler.GetString(resource, "DependentProgram"),
                            Description      = ResultObjectHandler.GetString(resource, "Description"),
                            PackageName      = ResultObjectHandler.GetString(resource, "PackageName"),
                            PackageID        = ResultObjectHandler.GetString(resource, "PackageID"),
                            ID = packageID + ";;" + programName,
                            //Name = PackageName + " (" + ProgramName + ")";
                            Name = programName
                        });
                    }
                }
            }
            catch { }

            querydata.Properties = propertylist;
            return(querydata);
        }
Beispiel #21
0
        public NeoQueryData CollectData()
        {
            NeoQueryData  querydata    = new NeoQueryData();
            List <object> propertylist = new List <object>();

            querydata.Properties = propertylist;

            try
            {
                // This query selects all collections
                string cmquery = "select * from SMS_DeploymentSummary";

                // Run query
                using (IResultObject results = Connector.Instance.Connection.QueryProcessor.ExecuteQuery(cmquery))
                {
                    // Enumerate through the collection of objects returned by the query.
                    foreach (IResultObject resource in results)
                    {
                        string ciid = ResultObjectHandler.GetString(resource, "CI_ID");
                        if (string.IsNullOrWhiteSpace(ciid))
                        {
                            ciid = ResultObjectHandler.GetString(resource, "PackageID");
                        }

                        string intent = string.Empty;
                        switch (ResultObjectHandler.GetInt(resource, "DeploymentIntent"))
                        {
                        case 1:
                            intent = "Install";
                            break;

                        case 2:
                            intent = "Uninstall";
                            break;

                        case 3:
                            intent = "Preflight";
                            break;

                        default:
                            break;
                        }

                        propertylist.Add(new
                        {
                            CollectionID = ResultObjectHandler.GetString(resource, "CollectionID"),
                            //CollectionName = ResultObjectHandler.GetString(resource, "CollectionName"),
                            DeploymentID     = ResultObjectHandler.GetString(resource, "DeploymentID"),
                            DeploymentIntent = intent,
                            SoftwareName     = ResultObjectHandler.GetString(resource, "SoftwareName"),
                            //PackageID = ResultObjectHandler.GetString(resource, "PackageID"),
                            //ProgramName = ResultObjectHandler.GetString(resource, "ProgramName"),
                            CIID = ciid
                                   //FeatureType = ((SccmItemType)ResultObjectHandler.GetInt(resource, "FeatureType")).ToString()
                        });
                    }
                }
            }
            catch { }

            return(querydata);
        }
        public NeoQueryData CollectData()
        {
            NeoQueryData querydata = new NeoQueryData();

            return(querydata);
        }
Beispiel #23
0
        public NeoQueryData CollectData()
        {
            NeoQueryData  querydata    = new NeoQueryData();
            List <object> propertylist = new List <object>();

            try
            {
                using (PrincipalSearcher principalSearcher = new PrincipalSearcher(new UserPrincipal(this._context)))
                {
                    try
                    {
                        DirectorySearcher searcher = principalSearcher.GetUnderlyingSearcher() as DirectorySearcher;
                        if (searcher != null)
                        {
                            searcher.Filter      = ("(&(objectCategory=group))");
                            searcher.SearchScope = SearchScope.Subtree;
                            searcher.PropertiesToLoad.Add("cn");
                            searcher.PropertiesToLoad.Add("memberof");
                            searcher.PropertiesToLoad.Add("name");
                            searcher.PropertiesToLoad.Add("samaccountname");
                            searcher.PropertiesToLoad.Add("grouptype");
                            searcher.PropertiesToLoad.Add("member");
                            searcher.PropertiesToLoad.Add("objectcategory");
                            searcher.PropertiesToLoad.Add("objectSid");
                            searcher.PropertiesToLoad.Add("distinguishedName");
                            searcher.PropertiesToLoad.Add("description");
                            searcher.PropertiesToLoad.Add("info");

                            searcher.PageSize = 1000;
                            SearchResultCollection results = searcher.FindAll();

                            foreach (SearchResult result in results)
                            {
                                string id      = ADSearchResultConverter.GetSidAsString(result);
                                string dn      = ADSearchResultConverter.GetSinglestringValue(result, "distinguishedname");
                                var    members = ADSearchResultConverter.GetStringList(result, "member");

                                propertylist.Add(new
                                {
                                    name = ADSearchResultConverter.GetSinglestringValue(result, "Name"),
                                    dn,
                                    description = ADSearchResultConverter.GetSinglestringValue(result, "Description"),
                                    id,
                                    info           = ADSearchResultConverter.GetSinglestringValue(result, "info"),
                                    grouptype      = GetTypeAndScope(ADSearchResultConverter.GetSinglestringValue(result, "grouptype")),
                                    samaccountname = ADSearchResultConverter.GetSinglestringValue(result, "samaccountname"),
                                    members,
                                    rid         = ADSearchResultConverter.GetRidFromSid(id),
                                    path        = dn,
                                    membercount = members.Count
                                });

                                foreach (string memberdn in members)
                                {
                                    this.GroupMemberships.Add(new { id, memberdn });
                                }
                            }
                        }
                        else
                        {
                            Program.ExitError("Error retrieving groups from AD", ErrorCodes.GroupsCollectorSearcherNull);
                        }
                    }
                    catch (Exception e)
                    {
                        Program.ExitError(e, "Error retrieving groups from AD", ErrorCodes.GroupsCollectorException);
                    }
                }
            }
            catch { }

            querydata.Properties = propertylist;
            return(querydata);
        }
Beispiel #24
0
        static void Main(string[] args)
        {
            Stopwatch totaltimer = new Stopwatch();

            string _appdir       = AppDomain.CurrentDomain.BaseDirectory;
            string neoconfigfile = _appdir + @"\config\neoconfig.json";
            string configfile    = _appdir + @"\config\adconfig.json";

            NeoWriter.ScanID = ShortGuid.NewGuid().ToString();

            IDriver          driver  = null;
            PrincipalContext context = null;

            totaltimer.Start();
            try
            {
                foreach (string arg in args)
                {
                    string[] param = arg.Split(new[] { ":" }, 2, StringSplitOptions.None);
                    switch (param[0].ToUpper())
                    {
                    case "/?":
                        ShowUsage();
                        Environment.Exit(0);
                        break;

                    case "/CONFIG":
                        configfile = param[1];
                        break;

                    case "/BATCH":
                        _batchmode = true;
                        break;

                    default:
                        break;
                    }
                }
            }
            catch
            {
                Console.WriteLine("There is a problem with arguments: " + string.Join(" ", args));
                Console.WriteLine("");
                ShowUsage();
                ExitError(1);
            }


            //load the config
            try
            {
                using (Configuration config = Configuration.LoadConfiguration(configfile))
                {
                    if (string.IsNullOrEmpty(config.ID))
                    {
                        Console.WriteLine("Your configuration does not have a scanner ID. A random ID will be generated for you below:");
                        Console.WriteLine(ShortGuid.NewGuid().ToString());
                        Console.WriteLine();
                        ExitError(2);
                    }
                    NeoWriter.ScannerID = config.ID;
                    context             = Connector.CreatePrincipalContext(config);
                }
            }
            catch (Exception e)
            {
                ExitError(e, "There was an error loading your configuration", 1);
            }



            //load the neo4j config
            try
            {
                using (NeoConfiguration config = NeoConfiguration.LoadConfigurationFile(neoconfigfile))
                {
                    driver = Neo4jConnector.ConnectToNeo(config);
                }
            }
            catch (Exception e)
            {
                ExitError(e, "There was an error loading your neo4j configuration", 2);
            }


            Console.WriteLine($"Starting scan\nScanner ID: {NeoWriter.ScannerID}\nScan ID: {NeoWriter.ScanID}\n");


            NeoWriter.WriteHeaders();

            //write the foreign principals
            NeoWriter.WriteIDataCollector(new ForeignSecurityPrincipalCollector(context), driver, true, true);

            //process users
            NeoWriter.WriteIDataCollector(new UsersCollector(context), driver, true, true);

            //load the computers
            NeoWriter.WriteIDataCollector(new ComputersCollector(context), driver, true, true);

            //process groups
            GroupsCollector groupscollector = new GroupsCollector(context);

            NeoWriter.WriteIDataCollector(groupscollector, driver, true, true);
            NeoWriter.WriteIDataCollector(groupscollector.GetMembershipsCollector(), driver, true, true);

            //process foreign item connections
            NeoWriter.WriteIDataCollector(new ForeignSecurityPrincipalConnectionCollector(), driver, true, true);
            NeoWriter.WriteIDataCollector(new RemoteForeignSecurityPrincipalConnectionCollector(), driver, true, true);

            NeoQueryData nopropsdata = new NeoQueryData();

            nopropsdata.ScanID    = NeoWriter.ScanID;
            nopropsdata.ScannerID = NeoWriter.ScannerID;

            //create primary group mappings
            Console.Write("Setting primary groups");
            NeoWriter.RunQuery(StandAloneQueries.SetPrimaryGroupRelationships, nopropsdata, driver, true, true);

            Console.WriteLine();
            Console.WriteLine("*Cleaning up");

            //*cleanup deleted items
            //remove group memberships that have been deleted
            Console.Write("Deleted group memberships");
            NeoWriter.RunQuery(StandAloneQueries.DeletedGroupMemberships, nopropsdata, driver, true, true);

            Console.Write("Deleted foreign group memberships");
            NeoWriter.RunQuery(StandAloneQueries.DeletedForeignGroupMemberShips, nopropsdata, driver, true, true);

            //mark deleted objects
            Console.Write("Mark deleted users");
            NeoWriter.RunQuery(StandAloneQueries.GetMarkDeletedObjectsQuery(Types.User), nopropsdata, driver, true, true);

            Console.Write("Mark deleted computers");
            NeoWriter.RunQuery(StandAloneQueries.GetMarkDeletedObjectsQuery(Types.Computer), nopropsdata, driver, true, true);

            Console.Write("Mark deleted groups");
            NeoWriter.RunQuery(StandAloneQueries.GetMarkDeletedObjectsQuery(Types.Group), nopropsdata, driver, true, true);

            Console.WriteLine("*Finished cleaning up");
            Console.WriteLine();

            Console.Write("Setting group scopes");
            NeoWriter.RunQuery(StandAloneQueries.SetGroupScope, nopropsdata, driver, true, true);

            Console.Write("Updating member counts");
            NeoWriter.RunQuery(StandAloneQueries.UpdateMemberCounts, nopropsdata, driver, true, true);

            //cleanup
            driver.Dispose();
            context.Dispose();

            totaltimer.Stop();
            double totaltime = totaltimer.ElapsedMilliseconds / 1000;

            Console.WriteLine();
            Console.WriteLine("Finished in " + totaltime + "secs");
            if (_batchmode == true)
            {
                Console.Write("Exiting.");
                for (int i = 0; i < 3; i++)
                {
                    System.Threading.Thread.Sleep(500);
                    Console.Write(".");
                }
            }
            else
            {
                Console.WriteLine("Press enter to exit");
                Console.ReadLine();
            }
        }
Beispiel #25
0
        public async Task <NeoQueryData> CollectDataAsync()
        {
            NeoQueryData querydata = new NeoQueryData();

            if (this.GroupIDs?.Count > 0)
            {
                Dictionary <string, string> idmappings = new Dictionary <string, string>();  //mapping dictionary for which groupid is associated with which request id
                List <object> propertylist             = new List <object>();
                int           requestcount             = 0;

                var enumerator = this.GroupIDs.GetEnumerator();
                BatchRequestContent batchRequestContent;

                using (HttpClient httpClient = await Connector.Instance.GetHttpClientWithToken())
                {
                    while (enumerator.MoveNext())
                    {
                        batchRequestContent = new BatchRequestContent();

                        //create the 20 batch requests
                        for (int i = 0; i < 20; i++)
                        {
                            string groupid   = enumerator.Current;
                            string requestid = requestcount.ToString();
                            idmappings.Add(requestid, groupid);
                            HttpRequestMessage requestmessage = new HttpRequestMessage(HttpMethod.Get, Connector.Instance.RootUrl + "/groups/" + groupid + "/members?$select=id");
                            batchRequestContent.AddBatchRequestStep(new BatchRequestStep(requestid, requestmessage, null));

                            requestcount++;

                            if (enumerator.MoveNext() == false)
                            {
                                break;
                            }
                        }

                        // now make the request, passing in the anonymous response handler
                        await Connector.Instance.MakeBatchRequest(httpClient, batchRequestContent, async (Dictionary <string, HttpResponseMessage> responses) =>
                        {
                            foreach (string key in responses.Keys)
                            {
                                string groupid;
                                if (idmappings.TryGetValue(key, out groupid))
                                {
                                    HttpResponseMessage httpResponseMsg;

                                    if (responses.TryGetValue(key, out httpResponseMsg))
                                    {
                                        string rawdata = await httpResponseMsg.Content.ReadAsStringAsync();
                                        BatchRequestResponseSimple simpleresponse = JsonConvert.DeserializeObject <BatchRequestResponseSimple>(rawdata);
                                        foreach (BatchRequestResponseValueSimple val in simpleresponse.Values)
                                        {
                                            propertylist.Add(new
                                            {
                                                groupid  = groupid,
                                                memberid = val.ID
                                            });
                                        }
                                    }
                                }
                            }
                        });
                    }
                }

                querydata.Properties = propertylist;
            }

            return(querydata);
        }
        public NeoQueryData CollectData()
        {
            NeoQueryData  querydata    = new NeoQueryData();
            List <object> propertylist = new List <object>();

            querydata.Properties = propertylist;

            using (PrincipalSearcher principalSearcher = new PrincipalSearcher(new UserPrincipal(this._context)))
            {
                try
                {
                    DirectorySearcher searcher = principalSearcher.GetUnderlyingSearcher() as DirectorySearcher;
                    if (searcher != null)
                    {
                        searcher.Filter      = ("(&(objectCategory=computer))");
                        searcher.SearchScope = SearchScope.Subtree;
                        searcher.PropertiesToLoad.Add("name");
                        searcher.PropertiesToLoad.Add("cn");
                        searcher.PropertiesToLoad.Add("samaccountname");
                        searcher.PropertiesToLoad.Add("objectcategory");
                        searcher.PropertiesToLoad.Add("objectSid");
                        searcher.PropertiesToLoad.Add("distinguishedName");
                        searcher.PropertiesToLoad.Add("operatingSystem");
                        searcher.PropertiesToLoad.Add("operatingSystemVersion");
                        searcher.PropertiesToLoad.Add("primaryGroupID");
                        searcher.PropertiesToLoad.Add("description");
                        searcher.PropertiesToLoad.Add("info");

                        searcher.PageSize = 1000;
                        SearchResultCollection results = searcher.FindAll();


                        foreach (SearchResult result in results)
                        {
                            string id = ADSearchResultConverter.GetSidAsString(result);
                            string dn = ADSearchResultConverter.GetSinglestringValue(result, "distinguishedname");

                            //find if the computer is enabled. use bitwise comparison
                            int  istate  = ADSearchResultConverter.GetIntSingleValue(result, "useraccountcontrol");
                            bool enabled = (((UserAccountControlDefinitions)istate & UserAccountControlDefinitions.ACCOUNTDISABLE) == UserAccountControlDefinitions.ACCOUNTDISABLE) ? false : true;

                            propertylist.Add(new
                            {
                                name = ADSearchResultConverter.GetSinglestringValue(result, "Name"),
                                dn,
                                description = ADSearchResultConverter.GetSinglestringValue(result, "Description"),
                                id,
                                info                   = ADSearchResultConverter.GetSinglestringValue(result, "info"),
                                samaccountname         = ADSearchResultConverter.GetSinglestringValue(result, "samaccountname"),
                                path                   = dn,
                                displayname            = ADSearchResultConverter.GetSinglestringValue(result, "displayname"),
                                operatingsystem        = ADSearchResultConverter.GetSinglestringValue(result, "operatingsystem"),
                                operatingsystemversion = ADSearchResultConverter.GetSinglestringValue(result, "operatingsystemversion"),
                                enabled,
                                primarygroupid = ADSearchResultConverter.GetSinglestringValue(result, "primaryGroupID")
                            });
                        }
                    }
                    else
                    {
                        Program.ExitError("Error retrieving computers from AD", ErrorCodes.ComputersCollectorSearcherNull);
                    }
                }
                catch (Exception e)
                {
                    //timer.Stop();
                    Program.ExitError(e, "Error retrieving computers from AD", ErrorCodes.ComputersCollectorSearcherException);
                }
            }
            return(querydata);
        }
Beispiel #27
0
        static void Main(string[] args)
        {
            string  appdir        = AppDomain.CurrentDomain.BaseDirectory;
            string  neoconfigfile = appdir + @"\config\neoconfig.json";
            string  configfile    = appdir + @"\config\ciconfig.json";
            bool    batchmode     = false;
            IDriver driver        = null;
            string  scanid        = ShortGuid.NewGuid().ToString();

            try
            {
                foreach (string arg in args)
                {
                    string[] param = arg.Split(new[] { ":" }, 2, StringSplitOptions.None);
                    switch (param[0].ToUpper())
                    {
                    case "/?":
                        ShowUsage();
                        Environment.Exit(0);
                        break;

                    case "/CONFIG":
                        configfile = param[1];
                        break;

                    case "/BATCH":
                        batchmode = true;
                        break;

                    default:
                        break;
                    }
                }
            }
            catch
            {
                Console.WriteLine("There is a problem with arguments: " + string.Join(" ", args));
                Console.WriteLine("");
                ShowUsage();
                Environment.Exit(1);
            }

            Configuration config = null;

            try
            {
                config = Configuration.LoadConfiguration(configfile);
            }
            catch (Exception e)
            {
                Console.WriteLine("There was an error loading config: " + configfile);
                Console.WriteLine(e.Message);
                Environment.Exit(2);
            }

            //load the neo4j config
            try
            {
                using (NeoConfiguration neoconfig = NeoConfiguration.LoadConfigurationFile(neoconfigfile))
                {
                    driver = Neo4jConnector.ConnectToNeo(neoconfig);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("There was an error loading your neo4j configuration");
                Console.WriteLine(e.Message);
                if (batchmode == false)
                {
                    Console.ReadLine();
                }
                Environment.Exit(2);
            }


            foreach (CustomItem item in config.Items)
            {
                using (ISession session = driver.Session())
                {
                    object prop;
                    if (item.Properties.TryGetValue(item.PrimaryProperty, out prop) == false)
                    {
                        Console.WriteLine("Primary property does not have a value");
                        Environment.Exit(10);
                    }
                    StringBuilder builder = new StringBuilder();
                    builder.AppendLine($"MERGE (n:{item.PrimaryType} {{{item.PrimaryProperty}:\"{prop}\"}})");

                    if (item.Types.Count > 1)
                    {
                        foreach (string type in item.Types)
                        {
                            if (type != item.PrimaryType)
                            {
                                builder.AppendLine($"SET n:{type}");
                            }
                        }
                    }

                    foreach (string key in item.Properties.Keys)
                    {
                        object o = item.Properties[key];
                        string s = o as string;
                        if (s == null)
                        {
                            builder.AppendLine($"SET n.{key}={o}");
                        }
                        else
                        {
                            builder.AppendLine($"SET n.{key}=\"{s}\"");
                        }
                    }
                    builder.AppendLine("RETURN n");

                    string       query = builder.ToString();
                    NeoQueryData data  = new NeoQueryData();
                    data.ScanID     = scanid;
                    data.ScannerID  = config.ScannerID;
                    data.Properties = config.Items;
                    NeoWriter.RunQuery(query, data, driver, true);
                }
            }



            Console.WriteLine();
            Console.WriteLine("Finished");
            if (batchmode == true)
            {
                Console.Write("Exiting.");
                for (int i = 0; i < 3; i++)
                {
                    System.Threading.Thread.Sleep(500);
                    Console.Write(".");
                }
            }
            else
            {
                Console.WriteLine("Press any key to exit");
                Console.ReadLine();
            }
        }
Beispiel #28
0
        public static void CleanupCmObjects(IDriver driver)
        {
            NeoQueryData collectionsdata = new NeoQueryData();

            collectionsdata.ScanID    = NeoWriter.ScanID;
            collectionsdata.ScannerID = NeoWriter.ScannerID;

            //nodes first
            List <string> cmnodetypes = new List <string> {
                Types.CMApplication,
                Types.CMPackage,
                Types.CMPackageProgram,
                Types.CMSoftwareUpdateGroup,
                Types.CMTaskSequence,
                Types.CMCollection,
                Types.CMDevice,
                Types.CMUser,
                Types.CMClientSettings
            };

            string query;

            foreach (string type in cmnodetypes)
            {
                query = "MATCH (n:" + type + ") " +
                        "WHERE n.scannerid=$ScannerID AND n.lastscan<>$ScanID " +
                        "DETACH DELETE n " +
                        "RETURN n";

                Console.Write("Cleaning up " + type);
                NeoWriter.RunQuery(query, collectionsdata, driver, true, true);
            }

            //any remaining edges
            List <string> cmreltypes = new List <string> {
                Types.CMLimitingCollection,
                Types.CMMemberOf,
                Types.CMReferences,
                Types.CMHasProgram,
                Types.CMHasObject,
                Types.CMHasDeployment
            };



            foreach (string type in cmreltypes)
            {
                query = "MATCH ()-[r:" + type + "]->() " +
                        "WHERE r.scannerid=$ScannerID AND r.lastscan<>$ScanID " +
                        "DELETE r " +
                        "RETURN r";

                Console.Write("Cleaning up " + type);
                NeoWriter.RunQuery(query, collectionsdata, driver, true, true);
            }


            //We don't delete software updates. MS might expire something which might remove it from SCCM.
            //We want to keep that info
            query = "MATCH (n:" + Types.CMSoftwareUpdate + ") " +
                    "WHERE n.scannerid=$ScannerID AND n.lastscan<>$ScanID " +
                    "SET n.IsExpired = true " +
                    "RETURN n";

            Console.Write("Finding expired updates");
            NeoWriter.RunQuery(query, collectionsdata, driver, true, true);
        }