Friday 27 June 2014

Find List items having unique permissions using PowerShell / List item permissions using Powershell


PowerShell Script to Find List items having Unique Permissions and to find out to whom List items are Shared with


Clear

Add-PSSnapin "Microsoft.SharePoint.PowerShell"

$web=Get-SPWeb -Identity "https://SP2013dev.com/sites/TestingPermissions/"

$ls=$web.Lists.TryGetList("CalcListTesting");

foreach($item in $ls.Items)
{


    if($item.HasUniqueRoleAssignments)
    {

     $i =1 ;

     Write-Host   $i "." $item.Title

    Write-Host "Groups who are associated with listitem  and their permissions are below "
   
    $item.RoleAssignments.Groups | Select Name, Roles
   
    $i=$i+1

     }
 }
 


Monday 9 June 2014

PowerShell Script to check for Feature Activation/ PowerShell Script to Activate Feature at Web Scope


Below PowerShell script will check for WebFeature with Feature id *********, is active or not,  in all the SiteCollections in a WebApplication.

If the feature is not active it will go and enable it. 

Get-SPFeature will get list of all Features which as different scopes Farm, WebApplication, Site, Web

As we are interested in Activating feature with Web Scope at all webs hence we are using scope as -Web.



cls
asnp "*sh*"
try
{
$web=Get-SPWebApplication   "http://SP2013LocalDev/" | Get-spsite -Limit All | get-spweb -Limit All | % {

$bool=Get-SPFeature -Web $_ | where {$_.Id -eq "54944497-1d5b-443d-aba9-d20991ed18bb"}
  
                    if(!$bool)
                    {
                    Enable-SPFeature -Identity "54944497-1d5b-443d-aba9-d20991ed18bb" -Url $_.Url
                    Write-Host  "Feature Activated"
                    }
          else
          {
          Write-Host "Feature is Active at" $_.Url
          }
     
       }
      
}
catch{
             $ErrorMessage = $_.Exception.Message
             Write-Host $web.Title  $ErrorMessage
       }


Wednesday 4 June 2014

List Item update using PowerShell / Replace list items using PowerShell

Replace List Items using PowerShell.

Item.Update()updates the " Modified "and "Modified By" fields as per the current logged in user and current server time. It also updates the version of the item if the Versioning option is Enabled in the List.

Item.SystemUpdate() -  If a user wishes he doesn't require to update Modified ", "Modified By" and  Version then user can for Systemupdate.


cls

Add-PSSnapin "Microsoft.SharePoint.Powershell"

$web =Get-SPWeb "http://weshare.sedwdev.local/sites/Russian/"

$list= $web.Lists.TryGetList("TestList")

$web.AllowUnsafeUpdates=$true

foreach($item in $list.Items)
{

$item["LinkData"] = $item["LinkData"].Replace("google","SharePoint2013")
$item["Editor"]=$item["Editor"]
$item["Modified"]=$item["Modified"]
$item.SystemUpdate();
}

#$list.Update();
Write-Host "Updated values in the list iteams are"

foreach($item in $list.Items)
{
$item["LinkData"]
}


OutPut :