【问题标题】:How to impersonate admin user for creating OneDrive or Personal Site?如何模拟管理员用户创建 OneDrive 或个人网站?
【发布时间】:2014-03-25 10:07:59
【问题描述】:

我正在使用 csom 在 Office 365 中创建个人网站,如下所示

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 而不适用于其他用户。 Yogesh 能够创建我的网站。只有 yogesh 拥有管理员权限。我想通过获取 yogesh 凭证为所有用户创建我的网站。有没有办法做到这一点?您能否提供我可以解决上述问题的任何代码或链接?

【问题讨论】:

    标签: c# sharepoint-clientobject sharepoint-userprofile onedrive


    【解决方案1】:

    您需要将管理员帐户设置为 SiteCollectionAdminstrator。在 PowerShell 中,它看起来像这样:

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

    来源:梭子鱼 OneDrive 权限设置指南:https://techlib.barracuda.com/bbs/onedriveadminpermissions

    编辑:我还没有找到不需要目标用户密码的 C# 解决方案,因此我将封装 Set-SPOUser PowerShell cmdlet。更多关注...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多