Category Archives: Powershell

Update Business Data Catalog Throttle Config with PowerShell

function UpdateBusinessDataCatalogThrottleConfig($maximum, $defaultVal)
{
    Write-Host "Update Business Data Catalog Throttle Config." -ForegroundColor cyan
    $bdcProxy = Get-SPServiceApplicationProxy | where {$_.GetType().FullName -eq (‘Microsoft.SharePoint.BusinessData.SharedService.’ + ‘BdcServiceApplicationProxy’)}

    $dbRule = Get-SPBusinessDataCatalogThrottleConfig -Scope Database -ThrottleType Items -ServiceApplicationProxy $bdcProxy

    Set-SPBusinessDataCatalogThrottleConfig -Identity $dbRule -Maximum $maximum -Default $defaultVal
}
Advertisements

Add Quick Launch Navigation Entries together with Localization Text using Powershell

Its a time where most SharePoint developers look to do everything possible with Powershell rather than writing thousands of C# code. One common simple such requirement is to add Navigation Entries to Quick Launch. This is specially very useful when you work with a site where publishing features are not available so that you can not use the GUI to add navigation entries either.

Here is the code,

    $webURL =  “http://mySPSiteURL/”
$enTitle = “Chaminda’s Blog ”
$frTitle = “Blog de Chaminda”
$urlLink =”https://chamindasomathilaka.wordpress.com”

$webs = Get-SPWeb -Identity $webURL -ea Stop

$navigation= $webs.Navigation.QuickLaunch

$culture = New-Object System.Globalization.Cultureinfo(“fr-FR”)
$cultureFrCA = New-Object System.Globalization.Cultureinfo(“fr-CA”)

$newnode = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode($enTitle, $urlLink, $true)

$addedNode = $navigation.AddAsLast($newnode)

$addedNode.TitleResource.SetValueForUICulture($culture, $frTitle)
$addedNode.TitleResource.SetValueForUICulture($cultureFrCA, $frTitle)

$addedNode.Update()

$webs.Update()

That is to add a Quick Launch navigation entry directing my blog with both English and French translation (this is in case you have both English and French languages are available on your site).

Same code can be used to add Navigation entry to Top Navigation Area as well. you just need to initialize $navigation variable with correct navigation.

   $navigation= $webs.Navigation.TopNavigationBar

Run a Powershell Script Block with Elevated Privileges

Familiar with this ?

SPSecurity.RunWithElevatedPrivileges(delegate
{

…….code to be run with Elevated Privileges

});

You can do the same with a Powershell Script as well,

[Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges(
    {
        $web = Get-SPWeb -identity $url
        $list = $web.Lists[“ListName”]
        $spListItems = $list.Items;
        $spListItems | Foreach-object {[MyProject.CustomCode]::MyMethod($_,$web)}
    }
)