Welcome to Powergui.org - an open source community for Windows Powershell

PowerGUI.org PowerGUI.org and blogs

Forums » PowerGUI User Discussions

Thread: How to provide Contribute permission to a sharepoint group?

This question is answered.


Permlink Replies: 5 - Pages: 1 - Last Post: Nov 12, 2009 9:16 AM by: antize
ssm225in

Posts: 22
Registered: 7/19/09
How to provide Contribute permission to a sharepoint group?
Posted: Nov 11, 2009 4:22 AM
 
  Click to reply to this thread Reply

Hi,


I created a new Sharepoint group using powershell. I need to provide "Contribute" permission on a sharepoint library for this group in the sharepoint site.


How do I achieve this?


REgards,




antize


Posts: 124
Registered: 2/21/09
Re: How to provide Contribute permission to a sharepoint group?
Posted: Nov 11, 2009 4:01 PM   in response to: ssm225in
 
  Click to reply to this thread Reply

This script looks like a good starting point > http://sharepointpsscripts.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=21699#DownloadId=77312

The RootWeb property is helpful. http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsite.rootweb.aspx

Will look into this more...



antize


Posts: 124
Registered: 2/21/09
Re: How to provide Contribute permission to a sharepoint group?
Posted: Nov 11, 2009 4:58 PM   in response to: ssm225in
 
  Click to reply to this thread Reply

Try this:

[string] $SiteUrl = "http://yoursite/"
[string] $GroupName = "yourgroupname"
[string] $RoleName = "Contribute"

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

$site = New-Object -typeName "Microsoft.SharePoint.SPSite" -argumentList $SiteUrl

$site.RootWeb.Roles[$RoleName].AddGroup($site.RootWeb.SiteGroups[$GroupName])

$site.Dispose()



ssm225in

Posts: 22
Registered: 7/19/09
Re: How to provide Contribute permission to a sharepoint group?
Posted: Nov 12, 2009 1:55 AM   in response to: antize
 
  Click to reply to this thread Reply

Hi,

But What about the document library on which I want to set my group with contribute permission? The script you provided just attached a role to the group but not to the particular document library..

Please clear me if I am wrong.




antize


Posts: 124
Registered: 2/21/09
Re: How to provide Contribute permission to a sharepoint group?
Posted: Nov 12, 2009 7:07 AM   in response to: ssm225in
 
  Click to reply to this thread Reply

So it seems like you created a group, now we have the code to assign a role to the group. Guess all that's left is to assign the group to the document library. I'll take a look.



antize


Posts: 124
Registered: 2/21/09
Re: How to provide Contribute permission to a sharepoint group?
Posted: Nov 12, 2009 9:16 AM   in response to: ssm225in
Answered
  Click to reply to this thread Reply

This was tricky ...

Try this -

[string] $SiteUrl = "http://dgappimg:1000/"
[string] $GroupName = "BFA Users Group"
[string] $RoleName = "Contribute"
[string] $LibraryName = "User Documentation"

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

$site = New-Object -typeName "Microsoft.SharePoint.SPSite" -argumentList $SiteUrl

$site.RootWeb.Lists[$LibraryName].BreakRoleInheritance($true)

$roleassignment = New-Object Microsoft.SharePoint.SPRoleAssignment ([Microsoft.SharePoint.SPPrincipal]$site.Rootweb.SiteGroups[$GroupName])

$roleassignment.RoleDefinitionBindings.Add($Site.RootWeb.RoleDefinitions[$RoleName])

$site.RootWeb.Lists[$LibraryName].RoleAssignments.Add($roleassignment)

$site.Dispose()

Converted to PowerShell from http://blogs.msdn.com/robgruen/



Legend
MVP: 2501 + pts
Guru: 2001 - 2500 pts
Expert: 751 - 2000 pts
Enthusiast: 31 - 750 pts
Novice: 0 - 30 pts
Moderators
Helpful answer (5 pts)
Answered (10 pts)

Point your RSS reader here for a feed of the latest messages in all forums