Thursday, 3 May 2012

"Administration service is stopped. Start the Microsoft SharePoint Foundation Administration 2010 service in order for the operation to continue." On Sharepoint 2010

This is one of this messages you don't expect, specially when you are trying to restore a backup at 4:00AM in the morning after seeing that the whole farm needs to be rebuilt. The last thing you need at 4:00AM is more problems, just because in four hours the company will start running.

To prevent that I have placed this little post, I hope it will will help.



So why is the "Administration service is stopped. Start the Microsoft SharePoint Foundation Administration 2010 service in order for the operation to continue." is popping up?. Well there is Windows Service called WSSADMIN.exe is used by SharePoint to perform backup/restore operations.



As you probably guessing the service has not been started, so just go to Services in Windows, and find a service called "SharePoint 2010 Administration".

Click on start and voila!

Friday, 6 January 2012

Adding a Custom Content Type to a document library with Powershell in Sharepoint 2010

Sometimes you will want to add your own Content Types (custom content types) to your list or document libraries (a list basically…). You can do it with the web interface, it is pretty easy, but what about if you need to perform this for 30,000 sites… you don’t want to spend the rest of the year clicking everywhere.

I have created a function , AddContentTypeToDocumentLibraryRemovingOtherContentType, which allows you to Add a Content Type (“DMSDocument”) and remove the default one (“Documents”). Be aware I will remove “Documents” from my list and add the content type from the site. Whart I am doing here is replacing the default “Document” content type with sophisticated Document content type I developed before called “DMSDocument”

You only need to pass:

  1. Name of the site URL
  2. Name of the Document Library
  3. Name of the Content Type to be added
  4. Name of the Content Type you want to remove from your Document Library.
 $_CurrentURL =  "http://sp_server"
 $_DocumentLibraryName = "Document Centre"
 $_ContentTypeToBeRemoved = "Document"
 $_ContentTypeToBeAdded = "DMSDocument"
 
 Function AddContentTypeToDocumentLibraryRemovingOtherContentType($_sCurrentURL,$_sDocumentLibraryName,$_sContentTypeToBeRemoved, $_sContentTypeToBeAdded)
 { 
 		## Getting the website...
  		$SPWeb = Get-SPWeb -Identity $_sCurrentURL		
		
		## Getting the Document Library (list) and enable Content Types
		$List = $SPWeb.Lists[$_sDocumentLibraryName]
		$List.ContentTypesEnabled = $true
		$List.update()
		
		## Getting the content types to be removed
		## NOTE: This particular one, "Document" lives in our list,
		##       so we remove it from there
		$DocumentCT = $List.ContentTypes[$_sContentTypeToBeRemoved]		
		## This Content type lives in the site, so we get it from there
    	         $CustomCT = $SPWeb.ContentTypes[$_sContentTypeToBeAdded]
    	         $List.ContentTypes.Delete($DocumentCT.Id)
		$List.ContentTypes.Add($CustomCT) 		
		$List.update()	
		
		## Disposing SPWEB object to avoid memory leaks.
		$SPWeb.Dispose()
}
AddContentTypeToDocumentLibraryRemovingOtherContentType $_CurrentURL $_DocumentLibraryName $_ContentTypeToBeRemoved $_ContentTypeToBeAdded

Conclusion: Powershell will bring you a high rate of productivity, but don’t forget to dispose the objects, otherwise you could cause memory leaks in your farm.

Wednesday, 21 December 2011

Unable to cast COM object of type 'Microsoft.SharePoint.Library.SPRequestInternalClass' to interface type 'Microsoft.SharePoint.Library.ISPRequest'.

I was working with PowerShell and Sharepoint 2010 and for some reason I have got this error:

Unable to cast COM object of type 'Microsoft.SharePoint.Library.SPRequestInternalClass' to interface type 'Microsoft.SharePoint.Library.ISPRequest'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{BDEADEBE-C265-11D0-BCED-00A0C90AB50F}' failed due to the following error: Bad variable type. (Exception from HRESULT: 0x80020008 (DISP_E_BADVARTYPE)).

This is the only stuff I was doing was adding a new library to my existing site. This is the code:

 [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
 $listTemplate = [Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary
 $spWeb = Get-SPWeb -Identity "http://sp_foundation_g/sites/Documents"
 $spWeb.Lists.Add("AllDocuments","My Doc Library",[Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary)
If you use Powershell you normally are administrator, but just in case I decided to check RunWithElevatedPrivileges in order to avoid any problem with the security. Everything was fixed straight away, and I didn’t get the error anymore, even if I tried to run the code without RunWithElevatedPrivileges. This is the code I ran to fix it:
[Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges(  
 {      
     [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
     $listTemplate = [Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary
     $spWeb = Get-SPWeb -Identity "http://sp_foundation_g/sites/Documents"
     $spWeb.Lists.Add("AllMydocuments","My Doc Library",[Microsoft.SharePoint.SPListTemplateType]::DocumentLibrary)
 }
)  
Conclusion: I have done plenty of research but I can’t find the answer of why this is happening, but the good news, it can be fixed!.