Revision #1

You are currently reviewing an older revision of this page.
Go to current version
 This topic is a how to.
Please keep it as clear and simple as possible. Avoid speculative discussions as well as a deep dive into underlying mechanisms or related technologies.

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\\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", "", "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()

See Also

Other Languages

This articles is also available in the following languages:

Italian (it-IT)

Revert to this revision