In SharePoint development, you often encounter site deployment, however, when we deploy to the formal environment from the development environment, especially the backup restore, all user groups are still the development environment, then we need to use PowerShell update;
PowerShell Command :
The Windows PowerShell Ise Editing tool is handy for writing PowerShell, and an add on the header is adding a reference to SharePoint;
PowerShell Full code:
PowerShell writing and CMD commands, C # code, there are some differences, especially the comparison of characters, string connections, variables and so on, we are interested or can look at the data PowerShell;
1add-PSSnapin Microsoft.SharePoint.PowerShell2 3$oldDomainName ="Uat";4$newDomainName ="Dev";5$SITEURL ="Http://devteamroom/sites/JianYu"6 7$site = get-SPSite $siteUrl8$web =$site. RootWeb;9$groupColl =$web. sitegroups;Ten One foreach($groupinch$groupColl) A { - foreach($userinch$group. Users) - { the if($user. Loginname.indexof ($oldDomainName)-gt0) - { -$username = $user. Loginname.split ("\\")[1]; -$group. AddUser ("i:0#.w| $newDomainName \ $username","","",""); + $group. Removeuser ($user); -write-host $username; + } A } at } - - $web. Dispose (); -$site. Dispose ();
Code logic
Logic is simple, find the site, get all the user groups of the top-level site, traverse each user, if it is the dev environment, add the same name of the production environment user name, while deleting the development environment users;
Advantages
High efficiency, fast speed, eliminating manual processing time;
Disadvantages
If the user name of the production and development environment is not the same, then the replacement work cannot be completed;
Summarize
PowerShell, which was introduced in the SharePoint 2010 release, didn't pay much attention to it before, but experienced the 2013 release and found that many times the PowerShell command line was much more efficient than the server-side object model, especially with its own Windows PowerShell ISE editing tools, debugging, use, are very convenient.
Of course, you can write a script when you need it and put it in a Windows scheduled task.
All right, here we go, rest and rest ...
SharePoint 2013 update users with PowerShell