Posts

Showing posts from November, 2013

Javascript: Get the current root url

This may not be the easiest way, but is certainly worked for me. var url = $(location).attr('href').replace(window.location.pathname, '').replace(window.location.search, '');

SharePoint: How do I add and remove unique permissions in Powershell?

Here are two useful scripts to help you on your way: function SetPermission($url, $list, $group, $permission) { $spWeb = Get-SPWeb $url $selectedList = $spWeb.Lists[$list] # Assign the "Contribute" RoleDefition to the site's visitors group $visitorsSPGroup = $spWeb.Groups[$group] If (! $selectedList.HasUniqueRoleAssignments) { $selectedList.BreakRoleInheritance($true) } $assignment = New-Object Microsoft.SharePoint.SPRoleAssignment($visitorsSPGroup) $assignment.RoleDefinitionBindings.Add(($spWeb.RoleDefinitions | Where-Object { $_.Type -eq $permission })) $selectedList.RoleAssignments.Add($assignment) $selectedList.Update() $spWeb.Dispose() } function RemovePermission($url, $list, $group) { $spWeb = Get-SPWeb $url $selectedList = $spWeb.Lists[$list] $visitorsSPGroup = $spWeb.Groups[$group] If (!$selectedList.HasUniqueRoleAssignments) { $selectedList.BreakRoleInheritance($true) } $web.AllowUnsafeUpdates = $true;

PowerShell: Loop through all the sites in a site collection (not recursive)

$site = Get-SPSite "http://mysitetosearch.com" $topWeb = Get-SPWeb $site.Url $site | Get-SPWeb -limit all | ForEach-Object { Write-Host "Found $_.Name"; }