Archive for the ‘PowerShell’ Category

Adding permission to list using powershell

$site = get-spsite("http://MySPSite")
$web = $site.RootWeb
$list = $web.Lists["MyList"]
$listitem = $list.Items[0] 
$user = $web.AllUsers["Domain\User"]
$role = $web.RoleDefinitions["Full Control"]
$roleassignment = New-Object Microsoft.SharePoint.SPRoleAssignment($user)
$roleassignment.RoleDefinitionBindings.Add($role)
$listitem.RoleAssignments.Add($roleassignment)
$listitem.Update()

I’m not sure if this will break inheritance automatically, you may have to explicitly do that for this to work.

Use set-spuser for site permissions

SYNTAX
        Set-SPUser [-Identity] <SPUserPipeBind> [-AddPermissionLevel <String[]>] [-AssignmentCollection 
        <SPAssignmentCollection>] [-ClearPermissions <SwitchParameter>] [-Confirm [<SwitchParameter>]] 
        [-DisplayName <String>] [-Email <String>] [-Group <SPGroupPipeBind>] [-IsSiteCollectionAdmin 
        <SwitchParameter>] [-PassThru <SwitchParameter>] [-RemovePermissionLevel <String[]>] [-SyncFromAD 
        <SwitchParameter>] [-Web <SPWebPipeBind>] [-WhatIf [<SwitchParameter>]] [<CommonParameters>]


    DESCRIPTION
        The Set-SPUser cmdlet configures properties of an existing user.

An Example:

Set-SPUser -Identity 'domain\name' -Web http://sp2test/site -AddPermissionLevel Read
Advertisements

Assign permissions for groups using PowerShell

site = get-spsite("http://MySPSite")
$web = $site.RootWeb
$list = $web.Lists["MyList"]
$listitem = $list.Items[0] 
$user = $web.AllUsers["Domain\User"]
$role = $web.RoleDefinitions["Full Control"]
$roleassignment = New-Object Microsoft.SharePoint.SPRoleAssignment($user)
$roleassignment.RoleDefinitionBindings.Add($role)
$listitem.RoleAssignments.Add($roleassignment)
$listitem.Update()

I’m not sure if this will break inheritance automatically, you may have to explicitly do that for this to work.

Use set-spuser for site permissions

SYNTAX
        Set-SPUser [-Identity] <SPUserPipeBind> [-AddPermissionLevel <String[]>] [-AssignmentCollection 
        <SPAssignmentCollection>] [-ClearPermissions <SwitchParameter>] [-Confirm [<SwitchParameter>]] 
        [-DisplayName <String>] [-Email <String>] [-Group <SPGroupPipeBind>] [-IsSiteCollectionAdmin 
        <SwitchParameter>] [-PassThru <SwitchParameter>] [-RemovePermissionLevel <String[]>] [-SyncFromAD 
        <SwitchParameter>] [-Web <SPWebPipeBind>] [-WhatIf [<SwitchParameter>]] [<CommonParameters>]


    DESCRIPTION
        The Set-SPUser cmdlet configures properties of an existing user.

An Example:

Set-SPUser -Identity 'domain\name' -Web http://sp2test/site -AddPermissionLevel Read

Edit site title and description in powershell

Please test this first in a development environment

Get-SPWeb -Identity http://SPServer | Set-SPWeb -Description "PowerShell is Cool"

$spWeb = Get-SPWeb -Identity http://SPServer 
$spWeb.Title = "PowerShell" 
$spWeb.TreeViewEnabled = "True" 
$spWeb.Update()

 

Brandon Atkinson – Blog: http://brandonatkinson.blogspot.com/

Basics of PowerShell with SharePoint

Basics of PowerShell with SharePoint.

using-powershell-with-sharepoint-understanding-sharepoint

 

$site = Get-SPSite http://portal.contoso.com/sites/some_site

This will get you an object of the Site Collection at that URL and put it in the variable $site.