不會維護網站群組並 SharePoint 入口網站 Server 2003 升級 SharePoint Server 2007 之後,將會指派給角色的使用者

文章翻譯 文章翻譯
文章編號: 938110 - 檢視此文章適用的產品。
全部展開 | 全部摺疊

徵狀

您從 Microsoft Office SharePoint 入口網站伺服器 2003年升級到 Microsoft Office SharePoint Server 2007 後已出現在 SharePoint 入口網站 Server 2003 中的網站群組不會維護 SharePoint Server 2007。 而是,個別使用者指派給角色 (也稱為使用權限等級)。 例如當您檢視網站權限] 清單中時,會看到一份使用者和角色之使用者已指派。您看不到網站群組。這有時可以弄亂網站權限] 清單中。

發生的原因

根據設計,SharePoint Server 2007 適用於這種方式。當您升級到 SharePoint Server 2007 時,SharePoint 入口網站 Server 2003 網站群組會轉換成 SharePoint Server 2007 角色。此外,SharePoint 入口網站 Server 2003 跨網站群組會轉換成 SharePoint Server 2007 群組。

其他可行方案

Microsoft 僅,為了說明提供程式設計範例,不提供任何明示或默示的保證。這包括,但不限於適售性或適合某特定用途之默示擔保責任。本文假設您已熟悉使用我們所示範的程式設計語言以及建立和偵錯程序所使用的工具。Microsoft 技術支援工程師可以協助解釋特定程序的功能。不過,不會修改這些範例以提供附加功能或建構程序,以符合您特定需求。

如果要解決這個問題,修改 SharePoint 入口網站 Server 2003 中的群組結構,讓升級作業會在 SharePoint Server 2007 中建立的角色而不是網站群組。 執行此動作填入 [SharePoint 入口網站 Server 2003 跨網站群組,根據現有的 SharePoint 入口網站 Server 2003 網站群組]。這樣的網站群組在升級作業期間建立 SharePoint Server 2007 中的方式。

下列是執行這些動作的程式碼的範例
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

/*
 
 * 
 * Usage
 *
 * 	Role2Group.exe -url foo -url bar [-fix]
 * 
 * Parameters
 * 
 *   1. A list of urls that specifies which SharePoint 
 *      virtual server to process.
 *   2. An optional flag (fix) to indicate whether 
 *      we should execute the code to move members that are 
 *      assigned to SPRoles or that are assigned to SPGroup. 
 *		By default, this is off to prevent any accidental updates to the database.
 * 
 * Details
 *
 *   The program will examine each Web that has unique permissions within each site 
 *   collection on each virtual server. It will examine each Role 
 *   and each site group within those Webs. This program will do the following: 
 *   1. Create a new cross-site group.
 *   2. Assign the new group to the role that is to be processed. 
 *   3. Move all the users who are assigned to the Role into the newly created group.
 * 
 *  	The following are the exceptions:
 *
 *      	- If no user is assigned to that role, no action is taken.
 *      	- If only one user is assigned to the admin role, no action is taken.
 *      	- If groups are assigned to that role, those groups will be warned
 *            because those groups cannot be assigned to another cross-site group.
 *      	- If domain groups are assigned to that role, the domain groups will 
 *            be warned because domain groups cannot be assigned to a cross-site group.
 */
namespace ConsoleApplication1
{
    static class Program
    {
        static int cWarning = 0;
        static int cError = 0;

        static void Main(string[] args)
        {
            if ((args.Length == 0) ||
                (args.Length == 1 && (args[0] == "-?" || args[0] == "-help")))
            {
                Console.WriteLine("");
                Console.WriteLine("Role2Group -url foo -url bar [-fix]");
                Console.WriteLine("");
                return;
            }

            ArrayList urls = new ArrayList();
            bool fix = false;

            for (int i = 0; i < args.Length; i++)
            {
                if (args[i] == "-url" && i + 1 < args.Length)
                {
                    urls.Add(args[i + 1]);
                    i++;
                    continue;
                }
                else if (args[i] == "-fix")
                {
                    fix = true;
                    continue;
                }
                else
                {
                    Console.WriteLine(String.Format("Unrecognized switch {0}", args[i]));
                    return;
                }
            }

            if (fix)
            {
                Console.WriteLine("You have specified the -fix option. This " + 
                    "will cause updates to your database");
                Console.WriteLine("Press [Enter] to continue, or [Ctrl+C] to exit...");
                Console.ReadLine();
            }

            SPGlobalAdmin globalAdmin = new SPGlobalAdmin();

            foreach (string url in urls)
            {
                Uri uri = new Uri(url);
                SPVirtualServer vs = globalAdmin.OpenVirtualServer(uri);

                if (vs == null)
                {
                    Console.WriteLine(String.Format(
                        "Cannot process virtual server at {0}.", url));
                    return;
                }

                if (vs.State != SPVirtualServerState.Ready)
                {
                    Console.WriteLine(String.Format(
                        "Skipping virtual server: {0}. Server state = {1}. " +
                        "Cannot process this virtual server.",
                        url, vs.State));
                    return;
                }

                try
                {
                    Console.WriteLine(String.Format("Processing virtual server {0}...", url));
                    ProcessOneVirtualServer(vs, fix);
                }
                catch (Exception e)
                {
                    cError++;
                    Console.WriteLine(String.Format("Error occured while " +
                        "processing virtual server {0}", url));
                    Console.WriteLine(e);
                }

                Console.WriteLine();
                Console.WriteLine("Finished. {0} Errors, {1} Warnings encountered", cError, cWarning);
            }
        }

        static private void WarnAboutDomainGroup(SPSite site, SPWeb web, SPRole role, SPUser user)
        {
            cWarning++;
            Console.WriteLine("WARNING: {0} is a domain group, which cannot " +
                "be assigned to a group", user, role.Name);
        }

        static private void WarnAboutGroup(SPSite site, SPWeb web, SPRole role, SPGroup group)
        {
            cWarning++;
            Console.WriteLine("WARNING: {0} is a cross site group, which " +
                "cannot be assigned to another cross site group ", 
                group.Name, role.Name);
        }

        static private SPGroup EnsureGroup(SPSite site, SPWeb web, SPUser user,
            string name, string description)
        {
            SPGroupCollection groups = web.SiteGroups;
            SPGroup group = null;
            int cTry = 0;
            string groupname = name;

            while (true)
            {
                try
                {
                    // if the group already exists, then modify 
                    // the original name with a number appendix
                    group = groups[groupname];
                    cTry++;
                    groupname = String.Format("{0}_{1}", name, cTry);
                }
                catch
                {
                    // break, if we have found a unique group name
                    break;
                }
            }

            groups.Add(groupname, user, user, description);
            group = groups[groupname];
            return group;
        }

        static private void ProcessOneWeb(SPSite site, SPWeb web, bool fix)
        {
            Console.WriteLine(string.Format("Processing web {0} ...", web.Url));

            StringBuilder sbGroupId = new StringBuilder("");
            SPRoleCollection roles = web.Roles;

            foreach (SPRole role in roles)
            {
                Console.WriteLine(string.Format("Processing role {0} ...", role.Name));

                SPGroup newgroup = null;
                string groupname = String.Format("{0} Group from {1}", role.Name, web.Title);

                // Get rid the following invalid chars from group 
                // name: / \ [ ] : | < > + = ; , ? * ' @  
                groupname = groupname.Replace('/', '_');
                groupname = groupname.Replace('\\', '_');
                groupname = groupname.Replace('[', '_');
                groupname = groupname.Replace(']', '_');
                groupname = groupname.Replace(':', '_');
                groupname = groupname.Replace('|', '_');
                groupname = groupname.Replace('<', '_');
                groupname = groupname.Replace('>', '_');
                groupname = groupname.Replace('+', '_');
                groupname = groupname.Replace('=', '_');
                groupname = groupname.Replace(';', '_');
                groupname = groupname.Replace(',', '_');
                groupname = groupname.Replace('?', '_');
                groupname = groupname.Replace('*', '_');
                groupname = groupname.Replace('\'', '_');
                groupname = groupname.Replace('@', '_');

                string groupdesc = String.Format("{0} Group from {1}. This " +
                    "group is automatically generated.", role.Name, web.Title);

                // there is nothing to do, if there is no individual user
                if (role.Type == SPRoleType.Guest || role.Users == null || role.Users.Count == 0)
                    continue;

                foreach (SPGroup group in role.Groups)
                {
                    WarnAboutGroup(site, web, role, group);
                }

                foreach (SPUser user in role.Users)
                {
                    if (user.IsDomainGroup)
                    {
                        WarnAboutDomainGroup(site, web, role, user);
                    }
                    else if (fix)
                    {
                        if (newgroup == null)
                        {
                            newgroup = EnsureGroup(site, web, user, groupname, groupdesc);
                            role.AddGroup(newgroup);

                            if (sbGroupId.Length == 0)
                            {
                                sbGroupId.Append(String.Format("{0}", newgroup.ID));
                            }
                            else
                            {
                                sbGroupId.Append(String.Format(";{0}", newgroup.ID));
                            }

                        }

                        newgroup.AddUser(user);
                    }
                }

                if (newgroup != null && fix)
                {
                    foreach (SPUser user in newgroup.Users)
                    {
                        try
                        {
                            role.RemoveUser(user);
                        }
                        catch
                        {
                            // We sometimes will fail, because we cannot remove
                            // all users from the administrator role.
                        }
                    }
                }
            }

            if (fix && sbGroupId.Length > 0)
            {
                web.Properties["vti_associategroups"] = sbGroupId.ToString();
                web.Properties.Update();
            }

            return;
        }

        static private void ProcessOneVirtualServer(SPVirtualServer curVS, bool fix)
        {
            SPSiteCollection sites = curVS.Sites;

            if (sites != null)
            {
                foreach (SPSite site in sites)
                {
                    if (site != null)
                    {
                        try
                        {
                            foreach (SPWeb web in site.AllWebs)
                            {
                                int template = web.WebTemplateId;

                                // If we have a Web with a template ID that is
                                //      20, 21, 22, 30, 31, 32, 33, 34, 35, or 36,
                                //   this is an area Web or a bucket Web from
                                //   an SPS 2003 instalation.
                                //  We will be unable to process these Webs because they use 
                                //  an external security provider. The external
                                //  security provider will deliberately return
                                //  ACCESS_DENIED to the WSS security object model. 
                                //  However, it is also unnecessary to process these Webs because
                                //  the SPS 2003 upgrade logic already does the role-to-group conversion.                               if ((template >= 20 && template <= 22) ||
                                    (template >= 30 && template <= 36))
                                {
                                    Console.WriteLine(string.Format("Skipping SPS2003 web {0} ...", web.Url));
                                    continue;
                                }

                                if (web.HasUniquePerm)
                                    ProcessOneWeb(site, web, fix);
                            }
                        }
                        finally
                        {
                            site.Close();
                        }
                    }
                }
            }
        }
    }
}

其他相關資訊

如需有關如何升級 SharePoint Server 2007 的詳細資訊,請造訪下列 Microsoft 網站]:
http://technet2.microsoft.com/Office/en-us/library/396c85d9-4b86-484e-9cc5-f6c4d725c5781033.mspx?mfr=true

屬性

文章編號: 938110 - 上次校閱: 2007年6月26日 - 版次: 1.1
這篇文章中的資訊適用於:
  • Microsoft Office SharePoint Server 2007
關鍵字:?
kbmt kbtshoot kbexpertiseinter kbprb KB938110 KbMtzh
機器翻譯
重要:本文是以 Microsoft 機器翻譯軟體翻譯而成,而非使用人工翻譯而成。Microsoft 同時提供使用者人工翻譯及機器翻譯兩個版本的文章,讓使用者可以依其使用語言使用知識庫中的所有文章。但是,機器翻譯的文章可能不盡完美。這些文章中也可能出現拼字、語意或文法上的錯誤,就像外國人在使用本國語言時可能發生的錯誤。Microsoft 不為內容的翻譯錯誤或客戶對該內容的使用所產生的任何錯誤或損害負責。Microsoft也同時將不斷地就機器翻譯軟體進行更新。
按一下這裡查看此文章的英文版本:938110
Microsoft及(或)其供應商不就任何在本伺服器上發表的文字資料及其相關圖表資訊的恰當性作任何承諾。所有文字資料及其相關圖表均以「現狀」供應,不負任何擔保責任。Microsoft及(或)其供應商謹此聲明,不負任何對與此資訊有關之擔保責任,包括關於適售性、適用於某一特定用途、權利或不侵權的明示或默示擔保責任。Microsoft及(或)其供應商無論如何不對因或與使用本伺服器上資訊或與資訊的實行有關而引起的契約、過失或其他侵權行為之訴訟中的特別的、間接的、衍生性的損害或任何因使用而喪失所導致的之損害、資料或利潤負任何責任。

提供意見

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com