All Role Definitions For SharePoint 2010 Site Using Web Services by PowerShell Scripting

Welcome to SharePoint 2010 once again after a long time. Normally we developers will get some quick requirement to get all the role definitions of the site quickly.

If it's a small site you can go into the Site Permissions and on the top you have Permission Levels where you can get the following levels as per the screen shot.

permission levels

permission levels description

But if it is a big site and you need to provide some kind of a document to the client then you can do it here using PowerShell.

A quick one that will involve a few seconds only.

Click on Start then right-click on SharePoint 2010 Management Shell and Run as Administrator.

PowerShell offers a powerful method of working with URIs by leveraging the System.Uri .NET class that offers many properties and methods that provide a way to easily manipulate and compare URIs. This class can be utilized using the [System.Uri] notation in PowerShell. You can get the full list of properties and methods by using the $uri command.

The following is the web service command you can test using your site.

Web Service Command: http://Your Site Name/_vti_bin/UserGroup.asmx

Here is the PowerShell you need to run.

Code

  1. ## Add in the Url  
  2.      $uri="Your Site/_vti_bin/UserGroup.asmx?wsdl"         
  3.      $usergroupWebServiceInput = New-WebServiceProxy -Uri $uri -UseDefaultCredential   
  4.      [System.Xml.XmlNode]$xmlNode=$usergroupWebServiceInput.GetRoleCollectionFromWeb()  
  5.       ## Here generate a xml file in the location containing the properties  
  6.      $output = New-Object -TypeName System.IO.StreamWriter -ArgumentList "D:\Manpreet\Webserviceresult.xml", $false  
  7.      $output.WriteLine("<?xml version=""1.0"" encoding=""utf-8"" ?>")  
  8.      $output.WriteLine($xmlNode.OuterXml)  
  9.      $output.WriteLine()   
  10.      $output.Dispose()  
Finally after running the script you will find the XML in your location and the output will be shown as per the screen shot.

XML Outpot

Keep Learning,
Cheers.

 

Up Next
    Ebook Download
    View all
    Learn
    View all