SharePoint 2013 update users with PowerShell

Source: Internet
Author: User

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 Complete 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.