Tag Archives: Reliable SharePoint Hosting

SharePoint 2013 Hosting – ASPHostPortal.com :: How to Add or Remove A New User to SharePoint Group Using Powershell Script

How to Add or Remove A New User to SharePoint Group Using Powershell Script

In SharePoint site you can see usually a lot of groups. Sometimes administrator gets a task to add user to several groups. If it’s 3-5 groups you can do it manually, but if you need to add user to 30 groups? I’m too lazy to do it manually and too smart not do it at all.

SharePoint 2013 Hosting

  1. Start your windows PowerShell on your computer.
  2. Right click and select Run as administrator option.
  3. Paste the below script on the PowerShell window and click the enter button.
  4. Check your SharePoint site Feature will activated successfully.

So let’s start out PowerShell ISE and connect SharePoint CMD-let:

if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) 
{ 
 Write-Host "Connect Sharepoint cmd-Let" 
 Add-PSSnapin Microsoft.SharePoint.PowerShell 
}

Let’s enter site collection url, username for inserting to groups and get array of destination SharePoint groups. For example, let this groups contain a string “admin”

$url = "http://user"
$userName = "user\testuser1"
$site = new-object Microsoft.SharePoint.SPSite($url) 
$web = $site.OpenWeb() 
$groups = $web.sitegroups
write-host "------get array of groups which contain a string "admin"-----" 
$myGroups = @(); 
foreach($group in $groups) { 
if($group -match "admin") { 
$myGroups += $group 
}

Go through each element of array and add user to SharePoint group

foreach ($gr in $myGroups) { 
#add user to SP Group
 Set-SPUser -Identity $userName -web $url -Group $gr 
 write-host "User " $userName "added to " $gr 
}

And if you made a false and, for example, entered wrong username, you can easily remove user from SharePoint groups with this PS-code:

foreach ($gr in $myGroups) { 
 $theGroup = $web.SiteGroups[$gr] 
 $theUser = $web.AllUsers.Item($userName) 
#Remove user from SP Group
 $theGroup.RemoveUser($theUser); 
 write-host "User " $userName " removed from " $gr
}

If you don’t want to collect these pieces here’s a full version:

if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) 
{ 
 Write-Host "Connect Sharepoint cmd-Let" 
 Add-PSSnapin Microsoft.SharePoint.PowerShell 
}
$url = "http://user"
$site = new-object Microsoft.SharePoint.SPSite($url) 
$web = $site.OpenWeb() 
$groups = $web.sitegroups 
$userName = "user\testuser1" 
write-host "--------------" 
$i = 0; 
$myGroups = @(); 
foreach($group in $groups) { 
 if($group -match "admin") { 
 $myGroups += $group 
 } 
} 
foreach ($gr in $myGroups) { 
 write-host $gr 
#add user to SP Group
 Set-SPUser -Identity $userName -web $url -Group $gr 
 $theGroup = $web.SiteGroups[$gr] 
 $theUser = $web.AllUsers.Item($userName) 
#Remove user from SP Group
# $theGroup.RemoveUser($theUser); 
 write-host "User " $userName "added to " $gr 
}

If there are non-english letters in a group name or if the group you need is on another site (but in this site collection), then you can have error on Set-SPUser command. In this case I can advice you to use another command $web.SiteGroups[group name].AddUser(user)

foreach ($gr in $myGroups) { 
 Write-Output "Группа: $gr " 
#alternative way to add user to SP Group 
 $theUser = $web.AllUsers.Item($userName)
 $web.SiteGroups[$gr].AddUser($theUser) 
 Write-Output "User $userName added to $gr" 
}

Cheap and Recommended SharePoint 2013 Hosting

ASPHostPortal.com is Perfect, suitable hosting plan for a starter in SharePoint. ASPHostPortal the leading provider of Windows hosting and affordable SharePoint Hosting. ASPHostPortal proudly working to help grow the backbone of the Internet, the millions of individuals, families, micro-businesses, small business, and fledgling online businesses. ASPHostPortal has ability to support the latest Microsoft and ASP.NET technology, such as: WebMatrix, WebDeploy, Visual Studio 2015, .NET 5/ASP.NET 4.5.2, ASP.NET MVC 6.0/5.2, Silverlight 6 and Visual Studio Lightswitch, ASPHostPortal guarantees the highest quality product, top security, and unshakeable reliability, carefully chose high-quality servers, networking, and infrastructure equipment to ensure the utmost reliability.

SharePoint Hosting :: How to Configure Page Output Caching in SharePoint 2013

This article will explains you how to configure page output caching in SharePoint 2013. In a normal operation, SharePoint generates ASP.NET pages dynamically from page templates and database content. These ASP.NET pages are then converted into HTML and sent to the client browser. This is a resource-intensive process. Page output caching stores the HTML output for specific SharePoint pages in memory, so that SharePoint does not need to regenerate a commonly-requested page every time.

ahp banner sharepoint-01
In addition, the page output cache can also store various versions of the same page. For example, anonymous users and authenticated users may see various versions of a specific page. SharePoint is able to cache both versions so requests from either type of user can be served without regenerating the page. Page output caching in SharePoint applies only to publishing pages. You configure page output caching at the site collection level through the Site Settings menu. The page output caching settings are only available if:

  • The SharePoint Server Publishing Infrastructure site collection-level feature is enabled.
  • The SharePoint Server Publishing site-level feature is enabled.

When it ideal to use page output cache

Page output caching can improve the speed at which commonly-requested pages are served and it can reduce the resource overhead associated with generating a page from database content. However, it does create a memory overhead on WFE servers, because cached pages are stored in memory. Generally speaking, page output caching is more suitable for publishing sites in which many users are likely to see the same content. There is little benefit to enabling page output caching on sites where the user experience is heavily individualized.

Page output cache profiles

You configure page output caching through cache profiles. Cache profiles specify the criteria used to perform caching, such as the retention period, whether items in the cache should be security trimmed and whether various page versions should be cached for specific parameters, HTTP headers, or query strings. When you enable page output caching, you select the cache profile you want to use for that site collection, site, or page layout. You can specify different cache profiles for anonymous and authenticated users.
Use the following procedure to create a new cache profile:

  1. On the root site for your SharePoint site collection, on the Settings menu, click Site settings.
  2. On the Site Settings page, under Site Collection Administration, click Site collection cache profiles.
  3. On the Cache Profiles page, click new item.
  4. Specify the criteria for you cache profile and then click Save.

Enabling page output caching

You can configure page output caching at the site collection level, the site level, or the page layout level.
The site collection-level settings specify default caching settings for the entire site collection. You can then override these settings where required at the site level or the page layout level.

Use the following procedure to configure page output caching at the site collection level:

  1. On the Settings menu, click Site settings.
  2. On the Site Settings page, under Site Collection Administration, click Site collection output cache.
  3. On the Output Cache Settings page, select Enable output cache.
  4. Under Default Page Output Cache Profile, on the Anonymous Cache Profile and Authenticated Cache Profile drop-down lists, click the required cache profile (or click Disabled).
  5. If you want individual sites to be able to override the default cache profile, under Page Output Cache Policy, click Publishing sites can use a different page output cache profile.
  6. If you want individual page layouts to be able to override the default cache profile, under Page Output Cache Policy, click Page layouts can use a different page output cache profile.
  7. If you want to include caching details on the SharePoint Developer Dashboard, under Debug Cache Information, click Enable debug cache information on pages.
  8. Click OK.

Configuring page output caching at the site level

Use the following procedure to configure page output caching at the site level:

  1.  On the Site Settings page, under Site Administration, click Site output cache.
  2.  On the Published Site Output Cache Settings page, under Anonymous Cache Profile, choose whether to inherit the default site collection cache profile or select a different cache profile.
  3.  On the Published Site Output Cache Settings page, under Authenticated Cache Profile, choose whether to inherit the default site collection cache profile or select a different cache profile.
  4.  Click OK.

Configuring page output caching at the page layout level

Use the following procedure to configure page output caching for individual page layouts:

  1. On the Site Settings page, under Web Designer Galleries, click Master pages and page layouts.
  2. On the Master Page Gallery page, locate the page layout you want to configure and then on the drop-down menu, click Edit Properties.
  3. In the Authenticated Cache Profile drop-down box, click the cache profile you want to use.
  4. In the Anonymous Cache Profile drop-down box, click the cache profile you want to use.
  5. Click Save.

 No#1 Best Recommended SharePoint 2013 Hosting

ASPHostPortal.com

ASPHostPortal.com  is Perfect, suitable hosting plan for a starter in SharePoint. ASPHostPortal  the leading provider of Windows hosting and affordable SharePoint Hosting. ASPHostPortal proudly working to help grow the backbone of the Internet, the millions of individuals, families, micro-businesses, small business, and fledgling online businesses. ASPHostPortal has ability to support the latest Microsoft and ASP.NET technology, such as: WebMatrix, WebDeploy, Visual Studio 2015, .NET 5/ASP.NET 4.5.2, ASP.NET MVC 6.0/5.2, Silverlight 6 and Visual Studio Lightswitch, ASPHostPortal guarantees the highest quality product, top security, and unshakeable reliability, carefully chose high-quality servers, networking, and infrastructure equipment to ensure the utmost reliability.

SharePoint 2013 Hosting – ASPHostPortal.com :: Creating Web Application From Existing Content Database

There are situations where you want to propagate one SharePoint web application to some other farm/machine. I feel the fastest way is to take content database backup and restore it in your destination farm. I have done so in last couple of weeks and I have leaned how to quickly do that. I was provided with content database backup and source code. That makes be able to restore site and generate wsps from source code.

banner promo-01Creating  content database from backup

Go to your database server and do following:

  • Create a blank database that will be used as content database
  • Restore a database using content database back up from source farm.

Creating a web application:

  • Go to sharepoint central administration and create a new web application
  • While creating a new web application, use existing content database in database section
  • Sometimes if your database is too large, web application creation takes too long and times out. Don’t worry at all. web application is still created successfully. It happened to me 4 times out of 5.

Validating the web application:

  • Go to sharepoint central administration, click on application management. In “Databases” section you will find “Manage content databases”
  • Choose your application and it will show database status and number of site collections. If you are not sure how many site collections are there in backup, anything greater than 0 is good news.

Configure web application to work properly. we are almost done now. Do following:

  • Go to sharepoint central administration
  • Click on “Application Management”
  • In “Site Collections” section click on “Change site collection administrators.
  • choose your web application set proper data in site admins.

Additional optional steps:
After performing all the above steps, it is still possible that you are not able to access your web application.

  • Last thing to do is to install and deploy wsp by using stsadm or your favorite method.

Conclusion:

It is always challenging to move applications from one farm to another. Specially when they are depending upon other service applications. In spent last two weeks to learn how to properly do that. I hope this will help you at some point during your sharepoint development.