Thursday, November 26, 2009

How to add users to the Visitor group of a Sharepoint 2010 application using Powershell

There has been a need in my company to add the users to the default visitor group of the sharepoint 2010 application. It is really very time consuming when you have to do it one by one using the Sharepoint UI. I have written a small script for which you can add the users to the default visitor group without any issues.
Here, in the below Script, users.txt contain the list of users that need to be added to the Visitors group...
------------------------------
$Users = Get-Content "C:\Users\service\Documents\PowerShell\users.txt"
foreach ($User in $Users)
{
$url = "http://server1"
$SPUser = New-SPUser -UserAlias $User -Web $url
$Group = "test"
$Owner = "service\account"
$SPSite = Get-SPSite $url
$SPWeb = Get-SPWeb $url
$OpenWeb = $SPSite.OpenWeb()
$OpenWeb.Update()
## can use the below two lines to add a single user to the Visitor Group
#$OpenWeb.SiteGroups.Web.AssociatedVisitorGroup.AddUser
#($Owner,"ps@ms.com",$Group,$Group)
$OpenWeb.SiteGroups.Web.AssociatedVisitorGroup.AddUser($SPUser)
$OpenWeb.Update()
$OpenWeb.Dispose()
}
--------------------------
Hope this helps some one...

Wednesday, November 18, 2009

Exception calling "Update" with "0" argument(s): "The web being updated was changed by an external process."

I came across the error "The web being updated was changed by an external process." when i was debugging a sharepoint code, in which I had changed the System Master Page and Site Master Page present in the page _Layouts/ChangeSiteMasterPage.aspx of the Publishing sharepoint site.

This issue came up because, the SPWeb object was not being disposed. As a result it was becoming stale. And when we try to call the update method of the SPweb object it fails.

The best way to handle this issue is to Dispose the SPWeb Object whenever possible and re-create it once again before you go ahead with any other sharpeoint change through code.

Hope this helps some one....

Wednesday, October 21, 2009

"The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again" error in SharePoint

When I tried to edit the home page of my application, I came across the error "The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again". This issue is caused because of security validation.

You can follow the steps to get rid of the error -
1> Go to Central Administration --> Application Management
2> Click on Web Application General Settings
3> Go to Web page Security Validation and select the Off radio button. Then click on OK.
4> Refresh the page and Iwas able to edit the page.

Hope this helps someone.

Wednesday, October 14, 2009

How to Disable My SIte and My Links from a Sharepoint site

There are always a need to disable my Site and My Links in MOSS 2007. Below are the steps inorder to disable the links -
1> Go to the Sharepoint Central admin page.
2> Then go to the SSP admin page.
3> Under the User Profiles and My Sites, click on the link "My Site settings".
4> In the left pane, there is a link "Personalization Services Permission". Click on that.
5> Select the user "NT AUTHORITY\authenticated users" and click on modify permissions of selected users.
6> Uncheck "Create Personal Site" and "Use Personal Features" and select "Manage Permissions" or any other permissions.

This shall fix the issue of removing the My Site and My Links from a Sharepoint Site.

Wednesday, October 7, 2009

An exception of type system.security.principal.identitynotmappedexception was thrown while configurating MOSS

I came across an issue in which MOSS was present in the server and i was doing a re-configuration of Sharepoint farm connecting it to a new server farm. I came across the error "An exception of type system.security.principal.identitynotmappedexception was thrown". I had checked that I had cleaned up the config database and also the admin content Database of previously set farm. I had manually deleted the web sites present in IIS related to sharepoint. I was not sure as to why this error came up.
Doing a bit of research, I came to know there was issue with the Central Admin App pool as it was running in another service account. I had deleted the Central admin website but had missed out to delete the App Pools related to sharepoint which created this issue.
Once I deleted the App Pools related to Sharepoint and started the configuration again. Everything worked perfectly fine.

Hope this experience helps someone.

STSADM technical reference

There is an excellent silverlight application which displays stsadm commands. Check out the below link for your reference.

http://technet.microsoft.com/en-us/office/sharepointserver/cc948709.aspx

Tuesday, October 6, 2009

error during SQL 2005 to SQL 2008 in-place upgrade

I came across a very wierd error when i was going for a in-place upgrade from SQL 2005 to SQL 2008. I had run the SQL Server upgrade Advisor to fix issues that needs to be taken care before the upgrade could take place.
I fixed the issues and then decided to do an upgrade. During the upgrade I came across an error - "Attributes do not match. Present attributes (Directory, Compressed, NotContentIndexed) , included attributes (0), excluded attributes (Archive, Compressed, Encrypted) "

To fix this kind of issue, it is important to note that the Microsoft SQL Server folder that is present in C:\program files of the server should neither be in compressed mode nor in archive mode.

If you come across this issue, please follow the below steps -
1> Check the folder "Microsoft SQL Server" in the path "C:\Program Files".
2> Right click on the Folder and select "Properties"
3> In the General Tab , there is an "Advanced" button.
4> Click on that button and see that the options "Folder is ready for archiving", "compress contents to save disk space" and "encrypt contents to secure data"are unchecked. If not, please uncheck it.

This shall resolve the issue with the SQL 2008 in-place upgrade.