1

I have got a good script, which work perfect at Server Sharepoint - Farm Solution. It create Unique Permission group to whole site. Here is a script:

    $spweb=Get-SPWeb -Identity "http://sha..";
$spRoleDefinition = New-Object Microsoft.SharePoint.SPRoleDefinition;
$spRoleDefinition.Name = "Submit only";
$spRoleDefinition.Description = "Can submit/add forms/files/items into library or list but cannot view/edit them.";
$spRoleDefinition.BasePermissions = "AddListItems, ViewPages, ViewFormPages, Open";
$spweb.RoleDefinitions.Add($spRoleDefinition);
$spweb.Dispose();

How Could I done , run this script on Sharepoint Online ?

1 Answer 1

1
Function Create-PermissionLevel {
[cmdletBinding()]
    param(
        [Microsoft.SharePoint.Client.ClientContext]$ctx,
        [string[]]$permissions,
        [string]$defName,
        [string]$desc
    )
    $roleDefs = $ctx.Web.RoleDefinitions
    $ctx.Load($roleDefs)
    $ctx.ExecuteQuery()
    $exists = $roleDefs | where {$_.Name -eq $defName}
    if (!$exists) {
        $roleDef = New-Object Microsoft.SharePoint.Client.RoleDefinitionCreationInformation
        $basePerm = New-Object Microsoft.SharePoint.Client.BasePermissions
        foreach($p in $permissions) {
            $basePerm.Set($p) 
        }
        $roleDef.Name = $defName
        $roleDef.Description = $desc
        $roleDef.BasePermissions = $basePerm    
        [void]$roleDefs.Add($roleDef)
        $ctx.ExecuteQuery()
        Write-Verbose "Created Permissions level $defName"
    }
    else {
        Write-Warning "Role Definition already exists!"
    }
}
#Get your context
$pass = Read-Host -Prompt "Password:" -AsSecureString
$user = "[email protected]"
$cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($user,$pass)
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext("https://abc.sharepoint.com/sites/site")
$ctx.Credentials = $cred
#define perms
$permissions = "AddListItems", "ViewPages", "ViewFormPages", "Open"
#call function
Create-PermissionLevel -ctx $ctx -permissions $permissions -defName "Submit only" -desc "Can submit/add forms/files/items into library or list but cannot view/edit them."
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.