What is Windows Powershell ? Windows PowerShell command-line interface is a new command-line tool and supporting scripting language from Microsoft that complements Cmd.exe in the Windows administration context. In the SharePoint administration context, Windows PowerShell supersedes the Stsadm.exe administration tool. Moving forward, you should use Windows PowerShell scripting technology to develop any new command-line scripts in SharePoint Foundation 2010. Firstly we need to load sharepoit assembly in powershell console which is the reference to all sharepoint objects. PS C:\Users\sunil> [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Sharepoint") GAC Version Location --- ------- -------- True v2.0.50727 C:\Windows\assembly\GAC_MSIL\Microsoft.SharePoint\12.0.0.0__71e9bce111e9429c\Microsoft.SharePo... Create a site object to hold the SPSite reference. PS C:\Users\sunil> $site=new-object Microsoft.Sharepoint.SPSite("http://mossportal") obtain an reference to the Web site that is associated with the URL that is used in an SPSite constructor. PS C:\Users\sunil> $web=$site.OpenWeb() Now defines the role assignments for a user. PS C:\Users\sunil> $spRoleAssignment=new object(SPRoleAssignment("mossportal\sunil", "sunilyadav165@gmail.com", "Sunil Yadav", "Sharepoint developer") Get the role from the web and set the base permission for a role definition.
>> $spRoleDefinition=$web.RoleDefinitions["Read"]
>> $spRoleAssignment.RoleDefinitionBindings.Add($spRoleDefinition)
Finally add the RoleAssignments to the current we and update the spweb object.
>> $web.RoleAssignments.Add($spRoleAssignment)
>> $web.Update()
This articles is also available in the following languages:
Richard Mueller edited Revision 3. Comment: Removed (en-US) from title, added tag
Richard Mueller edited Revision 4. Comment: Replaced RGB values with color names in HTML to restore colors
Luigi Bruno edited Revision 5. Comment: Added the "How To" tag and Wiki Message Template. Added the "See also" and "Other Languages" sections.
Craig Lussier edited Revision 2. Comment: added en-US to tags and title
Benoit Jester edited Revision 6. Comment: Add link to french article