Как выдать себя за администратора для создания OneDrive или личного сайта?

Я создаю персональный сайт в офисе 365, используя csom следующим образом

private void createPersonalSite()
        {
            try
            {
                //using (SPSite site = new SPSite("Site URL"))
                //{
                //SPServiceContext context = SPServiceContext.GetContext(site);
                var targetSite = new Uri("https://test/sites/18thFeb");
                var securePassword = new SecureString();
                foreach (char c in adminPassword)
                    securePassword.AppendChar(c);

                adminUserId = "yogesh@test.com";
                var onlineCredentials = new SharePointOnlineCredentials(adminUserId, securePassword);

                ClientContext clientContext = new ClientContext("https://test/sites/18thFeb");
                clientContext.Credentials = onlineCredentials;

                //Get user profile
                //// Get the PeopleManager object and then get the target user's properties.
                //Microsoft.SharePoint.Client.UserProfiles.PeopleManager peopleManager = new Microsoft.SharePoint.Client.UserProfiles.PeopleManager(clientContext);
                //Microsoft.SharePoint.Client.UserProfiles.PersonProperties personProperties = peopleManager.GetPropertiesFor("domainName\\userName");

                //personProperties.UserProfileProperties.

                Microsoft.SharePoint.Client.UserProfiles.ProfileLoader loader = Microsoft.SharePoint.Client.UserProfiles.ProfileLoader.GetProfileLoader(clientContext);
                Microsoft.SharePoint.Client.UserProfiles.UserProfile profile = loader.GetUserProfile();

                Microsoft.SharePoint.Client.Site personalSite = profile.PersonalSite;

                clientContext.Load(personalSite);
                clientContext.ExecuteQuery();

                // Let's check if the site already exists
                if (personalSite.ServerObjectIsNull.Value)
                {
                    // Let's queue the personal site creation using oob timer job based approach
                    // Using async mode, since end user could go away from browser, you could do this using oob web part as well
                    profile.CreatePersonalSiteEnque(true);
                    //clientContext.ExecuteQuery();
                }

            }
            catch
            {
                int a = 10;
            }
        }

Приведенный выше код отлично работает для пользователя yogesh, а не для других. Йогеш умеет создавать Мой сайт. Только йогеш имеет права администратора. Я хочу создать свой сайт для всех пользователей, приняв учетные данные Йогеша. Есть какой-либо способ сделать это? Можете ли вы предоставить мне какой-либо код или ссылку, с помощью которой я могу решить вышеуказанную проблему?

1 ответ

Вам необходимо установить учетную запись администратора в качестве SiteCollectionAdminstrator. В PowerShell это будет выглядеть так:

Set-SPOUser -Site $fullPath -LoginName $o365login -IsSiteCollectionAdmin $true

Источник: руководство по установке Barracuda для OneDrive. Разрешения: https://techlib.barracuda.com/bbs/onedriveadminpermissions

Изменить: я не нашел решение для C#, которое не требует пароля целевого пользователя, поэтому я собираюсь обернуть командлет Set-SPOUser PowerShell. Больше следовать...

Другие вопросы по тегам