public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            try
            {
                TenantContext.EnsureProperties(tssp => tssp.RootSiteUrl);
                var TenantUrl = TenantContext.RootSiteUrl.EnsureTrailingSlashLowered();


                // Set the Auth Realm for the Tenant Web Context
                using (var siteWeb = this.ClientContext.Clone(SiteUrl))
                {
                    var cq = new ChangeQuery
                    {
                        FetchLimit = 10,
                        Item       = true
                    };
                    var webAuthRealm = siteWeb.Web.GetChanges(cq);
                    siteWeb.Load(webAuthRealm);
                    siteWeb.ExecuteQuery();
                }

                var userPrincipalName = string.Format("{0}|{1}", ClaimIdentifier, this.UserName);
                DiscoveryGroups.Add(userPrincipalName);



                try
                {
                    SetSiteAdmin(SiteUrl, CurrentUserName, true);

                    using (var siteContext = this.ClientContext.Clone(SiteUrl))
                    {
                        Web _web = siteContext.Web;

                        ProcessSiteCollectionSubWeb(_web, true);

                        var siteProperties = GetSiteProperties(SiteUrl);
                    }
                }
                catch (Exception e)
                {
                    LogError(e, "Failed to processSiteCollection with url {0}", SiteUrl);
                }
                finally
                {
                    //SetSiteAdmin(_siteUrl, CurrentUserName);
                }
            }
            catch (Exception e)
            {
                LogError(e, "Failed in SetEveryoneGroup cmdlet {0}", e.Message);
            }

            WriteObject(Model);
        }
예제 #2
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            _siteActionLog = new List <ExtendSPOSiteModel>();

            try
            {
                TenantContext.EnsureProperties(tssp => tssp.RootSiteUrl);
                TenantUrl = TenantContext.RootSiteUrl;
                LogVerbose("Enumerating Site collections #|# UserID: {0} ......... ", CurrentUserName);

                var collectionOfSites = GetSiteCollections(true);
                foreach (var siteCollection in collectionOfSites.Where(w =>
                                                                       (!string.IsNullOrEmpty(SiteUrl) && w.Url.IndexOf(SiteUrl) > -1) || (string.IsNullOrEmpty(SiteUrl) && 1 == 1)))
                {
                    var _siteUrl   = siteCollection.Url;
                    var _totalWebs = siteCollection.WebsCount;
                    LogVerbose("Processing {0} owner {1}", siteCollection.Title, siteCollection.Owner);

                    try
                    {
                        SetSiteAdmin(_siteUrl, CurrentUserName, true);

                        using (var siteContext = this.ClientContext.Clone(_siteUrl))
                        {
                            Web _web          = siteContext.Web;
                            var extendedModel = new ExtendSPOSiteModel(siteCollection);

                            extendedModel = ProcessSiteCollectionSubWeb(extendedModel, _web, true);

                            // Add the Site collection to the report
                            _siteActionLog.Add(extendedModel);
                        }
                    }
                    catch (Exception e)
                    {
                        LogError(e, "Failed to processSiteCollection with url {0}", _siteUrl);
                    }
                    finally
                    {
                        //SetSiteAdmin(_siteUrl, CurrentUserName);
                    }
                }

                WriteObject(_siteActionLog, true);
            }
            catch (Exception e)
            {
                LogError(e, "Failed in SetEveryoneGroup cmdlet {0}", e.Message);
            }
        }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            var models = new List <SPUserDefinitionModel>();

            try
            {
                TenantContext.EnsureProperties(tssp => tssp.RootSiteUrl);
                var TenantUrl       = TenantContext.RootSiteUrl.EnsureTrailingSlashLowered();
                var MySiteTenantUrl = TenantUrl.Replace(".sharepoint.com", "-my.sharepoint.com");

                var i       = 1;
                var ilogger = new DefaultUsageLogger(LogVerbose, LogWarning, LogError);
                var odfb    = this.ClientContext.GetOneDriveSiteCollections(ilogger, MySiteTenantUrl, true);

                models = odfb.Select(s =>
                {
                    var UserName = s.UserName;
                    if (!string.IsNullOrEmpty(UserName))
                    {
                        UserName = UserName.ToString().Replace(";", ",");
                    }

                    var userObject = new SPUserDefinitionModel()
                    {
                        UserName  = UserName,
                        OD4BUrl   = s.Url,
                        UserIndex = i++
                    };

                    return(userObject);
                }).ToList();
            }
            catch (Exception ex)
            {
                LogError(ex, "Failed to retreive user profiles");
            }

            WriteObject(models, true);
        }
예제 #4
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            try
            {
                TenantContext.EnsureProperties(tctx => tctx.RootSiteUrl);
                var rootMySiteUrl = TenantContext.RootSiteUrl.Replace(".sharepoint.com", "-my.sharepoint.com");


                using (var ups = new UserProfileService(this.ClientContext, this.ClientContext.Url))
                {
                    var UserProfileResult = ups.OWService.GetUserProfileByIndex(-1);
                    var NumProfiles       = ups.OWService.GetUserProfileCount();
                    var i              = 1;
                    var tmpCount       = 0;
                    var nextValue      = UserProfileResult.NextValue;
                    var nextValueIndex = int.Parse(nextValue);

                    // As long as the next User profile is NOT the one we started with (at -1)...
                    while (nextValueIndex != -1)
                    {
                        LogVerbose("Examining profile {0} of {1}", i, NumProfiles);

                        // Look for the Personal Space object in the User Profile and retrieve it
                        // (PersonalSpace is the name of the path to a user's OneDrive for Business site. Users who have not yet created a
                        // OneDrive for Business site might not have this property set.)

                        var odbFound = false;
                        tmpCount++;

                        var Url = UserProfileResult.RetrieveUserProperty("PersonalSpace");
                        if (!string.IsNullOrEmpty(Url))
                        {
                            Url      = rootMySiteUrl + Url;
                            odbFound = true;
                        }

                        var UserName = UserProfileResult.RetrieveUserProperty("UserName");
                        if (!string.IsNullOrEmpty(UserName))
                        {
                            UserName = UserName.ToString().Replace(";", ",");
                        }

                        LogVerbose("MainLine {0} URL:{1} OD4B Found:{2} UserName:{3}", nextValueIndex, Url, odbFound, UserName);

                        var userObject = new
                        {
                            UserName  = UserName,
                            OD4BUrl   = Url,
                            UserIndex = nextValueIndex
                        };
                        WriteObject(userObject);

                        // And now we check the next profile the same way...
                        UserProfileResult = ups.OWService.GetUserProfileByIndex(nextValueIndex);
                        nextValue         = UserProfileResult.NextValue;
                        nextValueIndex    = int.Parse(nextValue);
                        i++;
                    }
                }
            }
            catch (Exception ex)
            {
                LogError(ex, "Failed to retreive user profiles");
            }
        }