Friday, February 28, 2014

"Metadata Navigation Settings" Link Missing in SharePoint 2013 Document Library?

Problem:
Metadata navigation settings in SharePoint document library is missing!

Metadata navigation makes it easier to find and dynamically filter content in large lists and libraries.  Once enabled, it uses a navigation tree in the quick launch.

Solution:
You must activate "Metadata Navigation and Filtering" Feature from Site features page! To enable Metadata Navigation and Filtering, Login as a Site Owner or Site Collection Administrator to your SharePoint site.
  • Click on Site Settings Icon >> Under Site Actions, click on Manage site features.
  • In the Features Page, click Activate button next to Metadata Navigation and Filtering.
metadata navigation settings missing sharepoint 2013
Now, You can configure metadata navigation to your SharePoint list and libraries.

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Tuesday, February 25, 2014

Add Custom Scope to SharePoint Search Dropdown using PowerShell

Requirement: We've created a custom search scope "Search All Documents" in SharePoint Central Admin and would like to include it in search scope drop downs of few site collections.

SharePoint 2010 add search scope to drop down:
Well, its a few-clicks job to include custom search scopes to search drop down in SharePoint. Here is how:
  1. Go to Site Actions >> Site Settings
  2. Click on "Search Scopes" link under Site collection administration
  3. Click on "Display Groups" link and choose "Search Dropdown"
    Edit Search Dropdown Scopes
  4. From here, we can include/exclude any scopes to search dropdown by simply selecting/deselecting check-boxes.Edit Search Scopes Dropdown
Add custom scope to SharePoint Search Scope Drop downs using PowerShell
While its not tedious to customize search scope dropdowns by following above steps for few site, We had to do it for all site collections under a particular managed path.(around 50!). Here is the PowerShell script to add custom search scopes to SharePoint search dropdown:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Set these three variables accordingly
$SiteURL  = "http://sharepoint.crescent.com/sites/operations/"
$CustomSearchScopeName = "Search All Documents"
$DisplayGroupName = "Search Dropdown"

#Get the Site Object
$Site= Get-SPSite $siteURL

#Initialize 
$SearchContext= [Microsoft.Office.Server.Search.Administration.SearchContext]::GetContext($site)
$Scopes= New-Object Microsoft.Office.Server.Search.Administration.Scopes($searchContext)

#Get the Display Group 
$SearchDropdownDisplayGroup =  $scopes.GetDisplayGroupsForSite($SiteURL) | Select-Object -First 1
#Get the custom scope
$CustomSearchScope = $Scopes.GetSharedScope($CustomSearchScopeName)

#Add custom scope to Display group
$SearchDropdownDisplayGroup.Add($CustomSearchScope)
$SearchDropdownDisplayGroup.Update()
 
See the result in action:Include Custom Scope to SharePoint Search Dropdown PowerShell

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Monday, February 24, 2014

Find All Inactive Features in SharePoint with PowerShell

What is inactive Feature in SharePoint? Well, Features which are installed but not activated anywhere!

Here is the PowerShell script to find inactive features for SharePoint:
Add-PSSnapin "Microsoft.SharePoint.Powershell" -ErrorAction SilentlyContinue

$InactiveFeatures = @()

#Get All installed features on respective scopes
$WebAppFeatures =  Get-SPFeature | Where-Object {$_.Scope -eq "WebApplication" }
$siteFeatures = Get-SPFeature | Where-Object {$_.Scope -eq "Site" } 
$WebFeatures = Get-SPFeature| Where-Object {$_.Scope -eq "Web" }

Write-host "Checking Web Application Scoped Features..."
   foreach ($WebAppFeature in $WebAppFeatures)
   {
       $Flag = $False
       foreach ($WebApp in Get-SPWebApplication)
    {
         if ((Get-SPFeature -WebApplication $WebApp.URL | Where-Object {$_.Id -eq $WebAppFeature.id}) -ne $null)
         {
          #We found that the Feature is active, Lets end up the loop
    $Flag = $True
    break 
         }
  }
  if($Flag -eq $False)
  {
   Write-Host "$($WebFeature.DisplayName) is not Active on any Web Application!)"
  }
   
   }

   Write-Host "`nChecking Site Collection Scoped Features..."
   foreach ($SiteFeature in $SiteFeatures)
   {
       $Flag = $False
       :WebAppLoop1 foreach ($WebApp in Get-SPWebApplication)
    {
      foreach($site in $WebApp.Sites)
   {
          if ((Get-SPFeature -Site $Site.URL | Where-Object {$_.Id -eq $SiteFeature.id}) -ne $null)
          {
           #We found that the Feature is active, Lets end up the loop
     $Flag = $True
     break WebAppLoop1 
          }
   }
  }
   if($Flag -eq $False)
   {
    Write-Host "$($SiteFeature.DisplayName) is not Active on Any Site Collection!"
   }   
   }

 Write-host "`nChecking Web Scoped Feature..."
   foreach ($WebFeature in $WebFeatures)
   {
       $Flag = $False
    #I'm limiting to a single web application, Remove ""http://sharepoint.crescent.com" to process all WebApps
       :WebAppLoop2 foreach ($WebApp in Get-SPWebApplication "http://sharepoint.crescent.com")
    {
         foreach($Site in $WebApp.Sites)
   {
       foreach($Web in $Site.AllWebs)
    {
           if ((Get-SPFeature -Web $Web.URL | Where-Object {$_.Id -eq $WebFeature.id}) -ne $null)
           {
            #We found that the Feature is active, Lets end up the loop
      $Flag = $True
      break WebAppLoop2 
           }
    }
   }
     }
   if($Flag -eq $False)
   {
    Write-Host "$($WebFeature.DisplayName) is not Active on Any Web!"
   }   
 }

Please note: There could be many OOTB features stay Inactive based on the site template we use. So, Use this script to get an insight of your custom features deployed to the SharePoint 2013/SharePoint 2010 environments.

To get a report on features activated on various scopes, refer:


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


SharePoint Features Usage Report using PowerShell

Task: Generate a report for All Installed/Activated Features for the entire SharePoint Environment. Here are some nifty PowerShell scripts to find features installed on the farm as well as specific features activated on a particular scope.

Get-SPFeature cmdlet:
Get-SPFeature cmdlet retrieves all features installed on the environment, when "Scope" parameter's value is not supplied. It gets all activated features on the particular scope, when you provide scope parameter: (Such as : -site "http://sharepointsite.com")

Get a list of all installed SharePoint features, Grouped by feature scope:
Get-SPFeature | Sort-Object Scope | Format-Table -GroupBy scope
SharePoint Features Usage Report using PowerShell

Lets export to a text file:
Get-SPFeature | Sort -Property Scope, DisplayName | Ft -Autosize -GroupBy Scope DisplayName, Id > D:\FeaturesReport.txt

To get all features activated at a particular web application scope, Use:
Get-SPFeature -WebApplication "web-app-url"
#Similarly:
#Get-SPFeature -Farm
#Get-SPFeature -Site $Site.URL
#Get-SPFeature -Web $web.URL

Get All Features along with their title:
Get-SPFeature | Format-Table @{Label='ID';Expression={$_.Id}}, 
@{Label='DisplayName';Expression={$_.DisplayName}}, 
@{Label='Title';Expression={$_.GetTitle(1033)}}, 
@{Label='Scope';Expression={$_.Scope}} -AutoSize | Out-File -Width 250 
D:\AllFeatures.txt

Get All Feature Tiles and Description, Activated on a Particular Site collection:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$siteurl = "http://sharepoint.crescent.com"

Get-SPFeature -Limit ALL -Site $siteurl | ForEach-Object {
 $data = @{ 
  Feature = $_.GetTitle(1033)
  Description = $_.GetDescription(1033)
    }
 New-Object PSObject -Property $data; 
} | Select-Object Feature, Description 

Find all/specific Feature in SharePoint 2013 / SharePoint 2010:
Lets find and list where a feature is activated.
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

$FeatureName = "TemplateDiscovery"
#We can also use "FeatureID" instead of Feature DisplayName 

# Get all Farm scoped features
#write-host "Farm scoped features:"
#Get-SPFeature -Farm 

# To Search for a specific Farm scoped feature:
Get-SPFeature -Farm | where { $_.DisplayName -eq $FeatureName } #Eg SpellChecking

 #Process All Web Applications
 ForEach ($WebApp in Get-SPWebApplication)
 {
 write-host "`nProcessing Web Application:" $webapp.url  
 #Get All Web Application Scoped features 
 #Get-SPFeature -WebApplication $WebApp.url 

 # To Search for a specific WebApplication scoped feature:
 Get-SPFeature -WebApplication $WebApp.url | where { $_.DisplayName -eq $FeatureName }

    #Process each site collection
  foreach ($site in $WebApp.sites) 
  {
  write-host "`tProcessing Site Collection: " $site.url 
  #Get All Site collection Scoped features 
  #Get-SPFeature -Site $site.url 

  # To Search for a specific Site Collection scoped feature:
  Get-SPFeature -Site $site.url | where { $_.DisplayName -eq $FeatureName }

      #Process each site
      foreach ($web in $site.AllWebs) 
      {
     write-host "`t`tProcessing Web: " $web.url 
     # Get All Web scoped features
     #Get-SPFeature -Web $web 

     # To Search for a specific Site Collection scoped feature:
     Get-SPFeature -Web $web | where { $_.DisplayName -eq $FeatureName }
       }
  }
 }

Feature inventory for SharePoint 2007 using STSADM:
Stsadm -o enumallwebs -includefeature

Using PowerShell to find all features in MOSS 2007:
This script gets all activated features scoped at web application, Site Collection, Site scopes:
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

Function global:Get-SPWebApplication($WebAppURL)
{
 return [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($WebAppURL)
}

  #Get the SharePoint Farm. Equallent to : Get-SPFarm commandlet
  $Farm = [Microsoft.SharePoint.Administration.SPFarm]::Local

  #Get All feature of the farm. Equallent to: Get-SPFeature commandlet
  $FarmFeatures= $Farm.FeatureDefinitions
  
  $WebAppURL = "http://SharePoint.Crescent.com"
  $WebApp = Get-SPWebApplication $WebAppURL
  
   #Scan Web Application Features
    Write-Host  "Features Activated at Web Application Level:"  -ForegroundColor DarkGreen

   foreach($feature in $WebApp.Features)
   {
      #Write-Host $feature.DefinitionId;
      Write-Host $farmfeatures[$feature.DefinitionId].DisplayName 
   }
  
  #Get All site collections of the Web Application  
  $SitesColl = $webApp.Sites  
  
  #Iterate through each site collection/sub-site
  foreach($Site in $SitesColl)
  {
   Write-Host "`nFeatures Activated at SITE:" $site.Url -ForegroundColor DarkGreen

   #Iterate through each feature activated at Site collection level
   foreach($feature in $site.Features)
   {
      #Write-Host $feature.DefinitionId;
      Write-Output $farmfeatures[$feature.DefinitionId].DisplayName;
   }
    foreach($web in $site.AllWebs)
    {
          Write-Host "`nFeatures Activated at WEB:" $web.Url -ForegroundColor DarkGreen
    #Iterate through each feature activated at web level
      foreach($Feature in $web.Features)
          {
        Write-Output $FarmFeatures[$Feature.DefinitionId].DisplayName;
     #Write-Output $FarmFeatures[$Feature.DefinitionId].GetTitle(1033);
          }
  }
  }

Get-SPFeature Cmdlet for SharePoint 2007:
Powershell script to report all SharePoint Farm Feature 
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

  #Get the SharePoint Farm. Equallent to : Get-SPFarm commandlet
  $Farm = [Microsoft.SharePoint.Administration.SPFarm]::Local

  #Get All feature of the farm. Equallent to: Get-SPFeature commandlet
  $FarmFeatures= $Farm.FeatureDefinitions
  $FarmFeatures | Select ID,DisplayName, Scope | Sort-Object Scope | Format-Table -GroupBy Scope
Tip: To find out all SharePoint enterprise feature usage, use: PremiumWebApplication, PremiumSite, PremiumWeb accordingly on Feature Display Names.

Find a Particular Feature's usage in SharePoint 2007:
#Get-SPWebApplication Cmdlet for MOSS 2007
Function global:Get-SPWebApplication($WebAppURL)
{  
   if($WebAppURL -eq $null)  #Get All Web Applications
    {
  $Farm = [Microsoft.SharePoint.Administration.SPFarm]::Local
    $websvcs = $farm.Services | where -FilterScript {$_.GetType() -eq [Microsoft.SharePoint.Administration.SPWebService]}
    $WebApps = @()
    foreach ($websvc in $websvcs) 
  {
      foreach ($WebApp in $websvc.WebApplications) 
   {
          $WebApps += $WebApp
      }
  }
   return $WebApps
  }
 else #Get Web Application for given URL
 {
  return [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($WebAppURL)
 }
}

  #Get the SharePoint Farm. Equallent to : Get-SPFarm commandlet
  $Farm = [Microsoft.SharePoint.Administration.SPFarm]::Local

  #Get All feature of the farm. Equallent to: Get-SPFeature commandlet
  $FarmFeatures= $Farm.FeatureDefinitions
  
  #Feature to Search
  $FeatureDisplayName = "IPFSWebFeatures" #Infopath Form Services Feature
  
  #Scan Farm Level Features
  $FarmLevelFeatures = $farm.FeatureDefinitions | Where-Object { ($_.Scope -eq "Farm") -and ($_.DisplayName -eq $FeatureDisplayName) }
  if($FarmLevelFeatures -ne $null)
  {
   "$($FeatureDisplayName) Installed at Farm Level!"
  }
   
   #Get all web applications and scan through 
   $WebApplications = Get-SPWebApplication "http://sharepoint.crescent.com"
   #To process all web applications, simply use: $WebApplications = Get-SPWebApplication 
   foreach($WebApp in $WebApplications)
   {
  Write-Host "Processing web Application : $($WebApp.url)"
  $WebAppLevelFeature = $webApp.Features |  Where-Object { $_.Definition.DisplayName -eq $FeatureDisplayName }
  #If Feature found
  if($WebAppLevelFeature -ne $null)
  {
  "$($FeatureDisplayName) Activated at Web Application $($webApp.URL)"
  }
    
  #Get All site collections of the Web Application  
  $SitesColl = $webApp.Sites  
  
  #Iterate through each site collection
  foreach($Site in $SitesColl)
  {
      #Write-host "Processing Site: $($Site.Url)"
   $SiteLevelFeature = $Site.Features |  Where-Object { $_.Definition.DisplayName -eq $FeatureDisplayName }
   #If Feature found
   if($SiteLevelFeature -ne $null)
     {
    "$($FeatureDisplayName) Activated at Site Collection $($Site.URL)"
     }
    
    #Enumerate each sub-site
    foreach($web in $site.AllWebs)
    {
         #Write-host "Processing Web: $($Web.Url)"
   $WebLevelFeature = $web.Features | Where-Object { $_.Definition.DisplayName -eq $FeatureDisplayName }
    #If Feature found
     if($WebLevelFeature -ne $null)
        {
      "$($FeatureDisplayName) Activated at Web Level $($web.URL)"
        }
     $web.Dispose()
  }
   $site.Dispose()
    }
 }

How do I find all custom features?
We can run Get-SPFeature on a fresh sharepoint machine, take that inventory in a csv file.
Run it again in your targt machine which has custom features and compare!

Lately, Found this script on Technet Forums:
Add-PSSnapin "Microsoft.SharePoint.Powershell" -ErrorAction SilentlyContinue

$siteurl = "http://sharepoint.crescent.com"
$Site = Get-SPSite $siteURL

#send all features to output file features.txt
$site.WebApplication.Farm.FeatureDefinitions `
| where-object {$_.solutionid -ne '00000000-0000-0000-0000-000000000000'} `
| Sort-Object solutionid,displayname `
| ft -property displayname,scope -auto -groupBy solutionid > "d:\features.txt"

#replace solutionId in features.txt with solution name
foreach($solution in $site.WebApplication.Farm.Solutions)
{
    (Get-Content "d:\features.txt") `
    | Foreach-Object {$_ -replace $solution.solutionid.ToString(), $solution.Name} `
    | Set-Content "D:\features.txt"
}

$site.Dispose()


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Sunday, February 23, 2014

Import XML File Data into SharePoint List using PowerShell

Requirement: We've an utility from third-party system that generates project data in XML format. We had to import those data to a list in the PMO site. In other words: We've to import from XML file to SharePoint list.

Here is a sample XML file, generated by the tool:
<?xml version="1.0"?>
<projects>
 <project id="PMO.1120">
  <description>GIS upgrade 2013 </description>
  <manager>global\E372440</manager>
  <cost>$35000</cost>
  <startdate>1/1/2014</startdate>
 </project>
 <project id="PMO.1121">
  <description>HRIT Asset Life Cycle Automation</description>
  <manager>AMER\E132321</manager>
  <cost>$63000</cost>
  <startdate>1/1/2014</startdate>
 </project>
</projects>  

Solution: Using PowerShell, lets import XML data into SharePoint list.

PowerShell script to read from XML and import to SharePoint list:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Set these two variables accordingly
$WebURL  = "http://project.crescent.com/"
$ListName = "External Projects"
$XMLFilePath = "D:\data\ExternalProjects.xml"

#Get the Web
$web = Get-SPWeb $WebURL
#Get the List
$ProjectList = $web.Lists[$ListName]

#import xml file
[xml]$ProjectXmlFile = Get-Content $XMLFilePath

foreach ($XMLProject in $ProjectXmlFile.projects.project)
 {
        $NewProject = $ProjectList.Items.Add()
  
        $NewProject["Project ID"] = $XMLProject.id
        $NewProject["Description"] = $XMLProject.description
        #Set the People Picker Field
        $NewProject["Project Manager"] = $web.EnsureUser($XMLProject.manager)
        $NewProject["Cost"] = $XMLProject.cost
        $NewProject["Start Date"] = $XMLProject.startdate
  
        $NewProject.Update()

        Write-Host "Project $($XMLProject.id) has been Added to External Projects list!"
 }
That's all! we are done importing XML data to sharepoint list with PowerShell!!

If you are looking for a way to Export SharePoint list items to XML, Refer: http://www.sharepointdiary.com/2014/03/export-list-items-to-xml-using-powershell.html

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Saturday, February 22, 2014

How to Add New List Item in SharePoint using PowerShell

My PowerShell scripts to add list item in SharePoint:

Add SharePoint list items using PowerShell
The syntax to add new list item in SharePoint using PowerShell, goes like this
#Get Web and List Objects
$Web = Get-SPWeb "http://sharepointsite.com"
$List = $Web.Lists["ListName"]

#Create a new item
$NewItem = $List.AddItem()
 
#Set Column values
$NewItem["ColumnName"] = "Field Value goes here!"
 
#Update the Item, so that it gets saved to the list
$NewItem.Update()

Add list item in SharePoint with PowerShell

Lets add new task to the task list using PowerShell: 
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Processing Variables
$WebURL="http://sharepoint.crescent.com"
$ListName="Tasks"

#Get Web and List Objects
$Web = Get-SPWeb $WebURL
$TaskList = $Web.Lists[$ListName]

#Create New Task Item
$NewTask = $TaskList.AddItem()
$NewTask["Title"] = "Migration Project - SOW"

#Add Date Time values
$NewTask["StartDate"] ="02/22/2015 00:00:00"
$NewTask["DueDate"] = "02/25/2015 02:00:00 PM"

#Add Assigned to People Picker field
$NewTask["AssignedTo"] = $Web.EnsureUser("Crescent\Salaudeen")

$NewTask.Update()

Result:
add sharepoint list items using powershell


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Thursday, February 20, 2014

Exclude a Column from SharePoint Search Crawl

Requirement:
We keep few fields for configuration in a custom SharePoint application and don't want those fields to appear in SharePoint Search results.

Solution:
SharePoint Fields/Columns has a property: NoCrawl, just turn it ON, we can exclude columns from SharePoint Search! Here is how I turned Off search visibility of a field using PowerShell:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Set these two variables accordingly
$WebURL  = "http://sharepoint.crescent.com"
$FieldName = "ConfigData"

 #Get the Web
 $web = Get-SPWeb $WebURL

 #Get the field
 $Field = $web.Fields[$FieldName]
  
    #Set the search prefererence
 $Field.NoCrawl = $true
  $Field.Update($true)
It takes effect after a search crawl takes place.

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Copy Files to SharePoint Servers Remotely using PowerShell

Requirement:
During a branding project, We had to deploy a logo file every time to all SharePoint servers by individually logging in to them and copy pasting given file to all SharePoint 2013 server's 15 hive. Wanted to do a bit automation with PowerShell here. Let the PowerShell do Copy-Paste for us.

PowerShell script to copy files to Servers:
$LogoPath = "D:\Branding\crescent-logo.png" 

#Define Array with List of servers
$WFEServers = ("G1V-SPS13001", "G1V-SPS13002", "G1V-SPS13003", "G1V-SPS13004", "G1V-SPS13005")

foreach ($Server in $WFEServers)
{
      #Destination path
      $Destination = "\\$Server\C$\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\IMAGES\crescent-logo.png"

      #Copy File from local to destination
      Copy-Item $LogoPath $Destination

      write-host "Copied to Server:"$Server
} 
You can run this script from your workstation. Just make sure the account in which you are running this script has Admin access on all of the servers listed.

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Find Who has Created / Modified a SharePoint View

Every wondered how to find the user who has created/modified a particular SharePoint view? and when it was created/modified? Well, There is no SharePoint UI to get these information! But using SharePoint object model, we can retrieve these data programmatically from SPFile object's properties.

Here is how I retrieved "Created By", "Created On", "Modified By", "Modified On" values using PowerShell:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Set these two variables accordingly
$WebURL  = "http://sharepoint.crescent.com/"
$ViewURL = "http://sharepoint.crescent.com/LegalDoc/AuthorView.aspx"

 #Get the Web
 $web = Get-SPWeb $WebURL

 #Get the View File
 $ViewFile = $web.GetFile($viewURL)
  
        Write-Host "Created By: " $ViewFile.Author 
 Write-Host "Created on: " $ViewFile.TimeCreated
        Write-Host "Modified By: " $ViewFile.ModifiedBy
 Write-Host "Modified On: " $ViewFile.TimeLastModified


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Tuesday, February 18, 2014

Get All SharePoint Site Collection Owners (Primary/Secondary Site Collection Administrators) - Report

Requirement is to find out owners of each SharePoint site collection in the environment.We needed this data to get approvals on critical changes and to inform site owners prior to maintenance windows.

Simple! Use STSADM command:
On SharePoint 2007 and above, STSADM command can be used to get primary owner details of site collections:
Syntax:
stsadm -0 enumsites -url <web-app-url>
E.g.
stsadm -0 enumsites -url "http://sharePoint.crescent.com" > SitesRpt.xml

This command enumerates all site collections and pulls site owner information. It also retrieves secondary owner, content database in which site collection exist and storage details of the site collection. Just open the generated XML file with Microsoft Excel.

Find Site Owners for All site collections using PowerShell:
Get-SPSite -Limit 'All' | select URL, Owner, SecondaryContact

For SharePoint 2007 Sites, The PowerShell script to get site Owners for all Site collections would be:
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

$WebAppUrl = "http://sharepoint.crescent.com" #Read-Host "Enter Web Application URL:"
$rootSite = New-Object Microsoft.SharePoint.SPSite($WebAppUrl)

#Get the Web Application from Site Collection
$WebApp = $rootSite.WebApplication

foreach($site in $WebApp.Sites)
{
    Write-Host "$($Site.Url) - $($Site.Owner) : $($Site.Owner.Email)"
    $site.Dispose()
}

Get All Site Owners in SharePoint 2010/2013:
On SharePoint 2010 and above, we can retrieve owner information with a single line of code:
Add-PSSnapin "Microsoft.SharePoint.Powershell" -ErrorAction SilentlyContinue

Get-SPWebApplication "http://sharepoint.crescent.com" | Get-SPSite | foreach-object { Write-host $_.Url - $_.Owner.Email}

Get me all Site collections I own:
This time, I had to find out all site collections a particular user owns. No worries, PowerShell is so powerful!

Add-PSSnapin "Microsoft.SharePoint.Powershell" -ErrorAction SilentlyContinue

Get-SPSite -Filter {$_.Owner -EQ "Global\Salaudeen"} -limit 100

For SharePoint Site Collection Administrators report, Refer: Site Collection Administrators Report for All SharePoint Sites

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Monday, February 17, 2014

SharePoint Number Column without Commas

Problem: SharePoint Number columns shows , (comma) in View/Display Forms. There are specific numeric columns, User wanted to display without commas.

There is no direct way to remove comma/avoid thousand separator in SharePoint Number fields, But the below tricks help to get SharePoint 2007/2010/2013 number column values without commas.

Solutions:
Here are some solutions to show number fields without comma:
  1. Use "Single Line of Text" instead of "Number" column type, if possible. (But this will not stop users from entering alpha characters!)
  2. Use an another Calculated column with formula: = TEXT( Number_Column_Name, "0") . If you need sorting, you can use: =FIXED(Number_Column_Name,0,TRUE) 
  3. Add Integer field programmatically (As there is no interface to do this!)
    #Get all site collections of the provided web application
    $Web = Get-SPWeb "http://projects.crescent.com/sites/Corp"
    
    $ListName = "ProjectBudget"
    
    $list = $web.lists[$ListName]
     
    $list.Fields.Add("TotalValue", [Microsoft.SharePoint.SPFieldType]::Integer, $false)
    
  4. If its for a view, You can use Dataview/XSLT web part with "format-number" formula as: <xsl:value-of select='format-number(TotalValue,"#.00") '/>
 sharepoint 2010 format number column without comma


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Wednesday, February 12, 2014

Add/Remove/Get Event Receivers in SharePoint with PowerShell

We usually use C# console application or feature activation code to register event receivers with the target list or library in SharePoint. At times, we may have to handle event receiver associations explicitly. Of course, there are some great tools in codeplex (E.g. http://speventreceiverman.codeplex.com/) to manage event receivers. However, in a production environment, which didn't allow me to use any such tools for security reasons, I'm left with the option: PowerShell. Hence, I'm sharing my PowerShell code snippets to manage event receivers in SharePoint using PowerShell.

Get all event receivers attached with a List:
Lets find in SharePoint 2010 PowerShell to get event receivers associated with a particular list.
 Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

 #Get the web
 $Web = Get-SPWeb "http://sharepoint.crescent.com"

 #Get the Target List
 $List = $Web.Lists["Documents"]

 #Retrieve all event receivers associated with the list
 $List.EventReceivers | Select Id, Type, Assembly, Class | FL 
 
Lets find all Event receivers on all sites in a web application:
Similarly, We can retrieve all event receivers associated with various lists and libraries across all site collection using the below PowerShell script.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$WebAppURL = "http://sharepoint.crescent.com"

 #Get All Webs
 $Webs = Get-SPWebApplication $WebAppURL | Get-SPSite -Limit All | Get-SPWeb 
 
 foreach($web in $Webs)
 {
  #Get Lists with Event receivers excluding System lists
  $web.lists | where { ($_.Author.LoginName -ne "SHAREPOINT\system") -and ($_.Hidden -eq $false) -and ($_.IsCatalog -eq $false) -and ($_.IsSiteAssetsLibrary -eq $false) -and ($_.EventReceivers.count -gt 0) } | Select Title, EventReceivers | FL
 } 

SharePoint 2010 powershell add event receiver
Usually, we create a C#.net console application to associate a event receiver to a particular list. This time, I tried with PowerShell script:

Lets add event receiver by creating the definition in PowerShell:
#Get the web
$Web = Get-SPWeb "http://sharepoint.crescent.com"

#Get the Target List
$List = $Web.Lists["Documents"]

#Add new event receiver definition
$def = $list.EventReceivers.Add()
$def.Assembly = "Crescent.DocRestrict, Version=1.0.0.0, Culture=neutral, PublicKeyToken=677b45b1314c252c"
$def.Class = "Crescent.Utilities.DocRestrict.Restrict" 
$def.Type = [Microsoft.SharePoint.SPEventReceiverType]::ItemAdded
$def.Name = "ItemAdded Event Receiver";
$def.SequenceNumber = 3000
$def.Synchronization = [Microsoft.SharePoint.SPEventReceiverSynchronization]::Synchronous
$def.Update() 

Alternatively, in SharePoint 2010 to add event receiver to list with PowerShell:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

 #Get the web
 $Web = Get-SPWeb "http://sharepoint.crescent.com"

 #Get the Target List
 $List = $Web.Lists["Documents"]

 #Retrieve all event receivers associated with the list
 #$List.EventReceivers | Select Id, Type, Assembly, Class | FL

 $Assembly = "Crescent.DocRestrict, Version=1.0.0.0, Culture=neutral, PublicKeyToken=677b45b1314c252c"
 $Class= "Crescent.Utilities.DocRestrict.Restrict"
 Write-Host "Attaching Event Receiver..."
 # sharepoint 2010 powershell register event receiver
 $list.EventReceivers.Add("ItemAdding", $Assembly , $Class)

How about content types? can add event receiver using PowerShell? why not?
#Get the content type
$ctype = $web.ContentTypes["content type name"]
#Add event receiver
$ctype.EventReceivers.Add("ItemAdding", "Assembly Name", "Class")

Remove Event Receiver:
To delete event receiver using PowerShell in SharePoint, here is the code:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

 #Get the web
 $Web = Get-SPWeb "http://sharepoint.crescent.com"

 #Get the Target List
 $List = $Web.Lists["Documents"]

 $Assembly = "Crescent.DocRestrict, Version=1.0.0.0, Culture=neutral, PublicKeyToken=677b45b1314c252c"

 $EventReceivers = $list.EventReceivers | Where {$_.Assembly -eq $assembly}

 if ($EventReceivers) #.Count -gt 0)
   {
      foreach($Receiver in $EventReceivers)
       {
         Write-Host "Deleting Event Receiver from " $list.RootFolder.ServerRelativeUrl 

         $Receiver.Delete()
        }
   } 
SharePoint PowerShell remove event receiver:
You can also delete a particular event receiver by its ID.
 #Get the web
 $Web = Get-SPWeb "http://sharepoint.crescent.com"

 #Get the Target List
 $List = $Web.Lists["Documents"]

 #Get all event receivers associated with the list
 $List.EventReceivers | Select Id, Type, Assembly, Class | FL 

#$EventReceiverID = "625c59a9-72d7-4479-a1e7-35f040e4f9a1"
#Uncomment below line to sharepoint 2010 remove event receiver from list powershell
#$list.EventReceivers[[GUID]$EventReceiverID].delete()

Remove Duplicate Event Receivers:
Duplicate instances of SharePoint event receivers is a known issue. They share a common assembly with different sequence numbers. So they fire twice.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

 #Get the web
 $Web = Get-SPWeb "http://sharepoint.crescent.com"

 #Get the Target List
 $List = $Web.Lists["Documents"]

 #Get all event receivers grouped by assembly/class/type
 $list.EventReceivers | Group-object assembly, class, type |  where { $_.Count -gt 1 } 

      #If any of assembly/class/type pairs are same, we have a duplicate!

     #Leave the first event receiver at 0th position and delete all other
     $list.EventReceivers | Group-object assembly, class, type |  where { $_.Count -gt 1 } |  foreach { $_.Group[1..50] } | foreach { $_.Delete() }
To Add event receivers with SharePoint list Programmatically, refer: sharepoint powershell add event receiver to list

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Friday, February 7, 2014

Enable NetBIOS Name for User Profile Service Application in SharePoint

We must enable NetBIOS for User Profile Service Application in SharePoint when Fully Qualified Domain Name is different than NetBIOS name. Ok. How to find NetBIOS name of your domain?
  1. Login to your Domain controller >> Open : Active Directory Users and Computers"  (Shortcut: dsa.msc)
  2. Right-click on your domain in the left pane and choose "Properties"
  3. Under "General" tab, Your domain name  and NetBIOS names will be listed. Your domain’s NetBIOS name is the domain name (pre-Windows 2000).
    Enable NetBIOS Name for User Profile Service Application in SharePoint
What's the problem if its not enabled? Inconsistency in SAMAccountName field which could lead to many other issues such as: Some features may not work due to this inconsistency (Instead of "YourCompanyName\User" it could be "YourComp\user") , UPS Field mappings such as "Manager" field may go wrong, etc.

Enable NetBIOS Name for User Profile Service Application:
So, You find your NetBIOS name is different from Domain name and want to enable NetBIOS name for your user profile service application, isn't it? Well, Here is the PowerShell script:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Variable for UPS Service Application - Set it according to your environment
$UPSDisplayName = "Hosting Farm User Profile Profile Service"

#Get User Profile Service Application
$ServiceApps = Get-SPServiceApplication

foreach ($sa in $ServiceApps)
{
    if ($sa.DisplayName -eq $UPSDisplayName)
        {$UserProfileServiceApp = $sa}
 }

#Get the current configuration
$UserProfileServiceApp.NetBIOSDomainNamesEnabled 

#Enable NetBIOS Domain name
$UserProfileServiceApp.NetBIOSDomainNamesEnabled = 1
$UserProfileServiceApp.Update()

Important: If you've already created any AD connections before you set NetBiosDomainNamesEnabled property, you MUST delete and recreate your AD connections under "Synchronization Connections" page.

Perform a IISReset and trigger full user profile Synchronization

Tail: In addition to "Replicate Directory Changes" Permission to all domains, You need to have this permssion granted for "Configuration" object as well.
  1. Launch ADSI Edit (Start >> Run >> ADSIEdit.msc )
  2. Actions >> Connect to >>  Under, “Select a well known Naming Context”, choose Configuration and click OK.
  3. Expand Configuration object and go to its properties page (right click >> properties)
  4. Select Security tab Add DOMAIN\UPSSyncAccount user and give it "Replicating Directory Changes" permissions


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Monday, February 3, 2014

SharePoint 2013 "Get Started with your site" Web Part - FAQs

"Getting Started" tiles are new addition to SharePoint 2013 team sites. These tiles intend to provide shortcuts to common actions, such as sharing your site, applying a theme. In SharePoint 2013, They replaces the “Getting Started” links from its previous version: SharePoint 2010.
sharepoint 2013 getting started web part
Disable Getting Started Web Part:
From the home page you can remove this web part by simply clicking on "REMOVE THIS" link as shown in the above image. But it remains in the gallery in the event you would like to have it added back to the site. Just edit the page >> Insert >> Web Part >> Choose "Getting Started with your site" under "Media and Content" group, to add it back to your home page.

You can also find "Getting Started" link which is pointing to "GettingStarted.aspx" page under site action menu in SharePoint 2013.
sharepoint 2013 get started with your site customize
This feature is automatically activated with the team site in SharePoint 2013. You can disable Getting Started menu item by going to Site Actions >> Site Settings >> Manage Site Features >> Deactivate "Getting Started" feature.
 sharepoint 2013 getting started web part edit
Disabling this feature removes the "Getting Started" link from site actions menu in SharePoint 2013, but doesn't remove "Get Started with Your Site" from home page. If you try to activate this feature again, it adds "Getting Started" web part to GettingStarted.aspx page one more time. So, activating and deactivating this feature just makes the page clumsy. Probably we can call it as a BUG? You can edit the page and remove unwanted web parts from it, If you would like to.
sharepoint 2013 get started with your site web part customize
Customize get started web part in SharePoint 2013
Want to customize get started web part in SharePoint 2013? You can create new promoted tiles web part add to home page. Here is how: Create Custom Promoted Link Tiles in SharePoint 2013

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Upload File to SharePoint using Web Services and PowerShell

Here is my PowerShell script to upload file to SharePoint document library using web services:
$SourceFile = "D:\Reports\MonthlyRpt-Jan14.csv"
$DestinationPath ="http://operations.crescent.com/Reports/MonthlyRpt-Jan14.csv" 

$WebServiceURL = "http://operations.crescent.com/_vti_bin/copy.asmx?WSDL" 
$CopyWebService = new-WebServiceProxy -Uri $WebServiceURL  -UseDefaultCredential

#For custom Credentials, use:
#$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList @($UserName,$SecurePasssword)
#$UserName = "Domain\UserName"
#$Password = "PASSWORD"
#$SecurePasssword = ConvertTo-SecureString -String $Password -AsPlainText -Force
#$CopyWebService= new-WebServiceProxy -Uri $WebServiceURL -Credential $cred 

#Get the File from Disk
$FileData = [System.IO.File]::ReadAllBytes($SourceFile)    
#Get Filename
$FileName = [System.IO.Path]::GetFileName($SourceFile).ToString()

$Metadata = @() 

$results = $null
#Upload file to SharePoint library using Web Service
$ret= $CopyWebService.CopyIntoItems($FileName, $DestinationPath, $Metadata, $FileData, [ref]$results)

Write-host "Upload Status:" $results[0].ErrorCode


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Upload Files to SharePoint Remotely using Web Client and PowerShell

If you want to upload file to SharePoint document library from client side (or remotely), Here is the nifty PowerShell code snippet.

Upload file to SharePoint - Web Client HTTP put method:
#Variable for Source folder in Local machine
$FilesLocation ="D:\Scripts\Reports\"
$TargetLocation="http://Operations.Crescent.com/Reports/"

#Create new web client object
$WebClient = new-object System.Net.WebClient
$WebClient.Credentials = [System.Net.CredentialCache]::DefaultCredentials

#Use these lines if you use different credentials
#$cred = new-object System.Net.NetworkCredential("USER NAME","PASSWORD","DOMAIN")
#$WebClient.credentials = $cred

#Target File Location to upload
function Set-DestinationFile($FileName)
 { 
   $TargetLocation + $(split-path -leaf $FileName)
 }

  #Iterate throgh each file and upload
  Get-ChildItem $FilesLocation | ForEach-Object {

  $DestinationFile= Set-DestinationFile $_;

  #upload file to sharepoint using webclient
  $WebClient.UploadFile($DestinationFile,"PUT", $_.FullName)
 } 


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Create Sharepoint Alert for a Group

SharePoint doesn't provide a direct way to create alerts for groups. Alerts are always targeted to individual user accounts in SharePoint. If you have a requirement to create alerts for a group of people, create a E-mail enabled AD security group and add alert to it from SharePoint.
sharepoint create group alert

Set alert to group in SharePoint using PowerShell:
Alternatively, You can use PowerShell to create a SharePoint alert for a group.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Variables to create group alert
$WebURL="http://intranet.crescent.com/sites/sales/" 
$GroupName="Sales Auditors"
$ListName="Documents"

#Get the objects
$Web = Get-SPWeb $WebURL
$Group = $web.Groups[$GroupName]
$List = $web.Lists[$ListName]

#Loop throgh each user in the group and create new alert
foreach ($user in $group.Users)
{
     #sharepoint set alert to group
     $alert = $user.Alerts.Add()
     $alert.Title = "New Sales Proposal Alert"
     $alert.AlertType = [Microsoft.SharePoint.SPAlertType]::List
     $alert.List = $List
     $alert.DeliveryChannels = [Microsoft.SharePoint.SPAlertDeliveryChannels]::Email
     $alert.EventType = [Microsoft.SharePoint.SPEventType]::Add
     $alert.AlertFrequency = [Microsoft.SharePoint.SPAlertFrequency]::Immediate
     $alert.Update()
}
Write-host "Alerts created for all users in the group:"$GroupName
$web.Dispose()
Related Post: Managing Alerts in SharePoint using PowerShell

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Sunday, February 2, 2014

Increase Maximum size of Site, List Templates in SharePoint

In SharePoint 2007, You can't save a list or site template (.stp ) file which is bigger than 10MB. MOSS 2007 gives an error message: "The list is too large to save as a template. The size of a template cannot exceed 10485760 bytes." When you try to save a list or site which by including its content which is more than 10 MB.

Fix is simple:
Just execute this stsadm command line from your SharePoint WFE server. Say, you want to allow site or list template up to 250 MB:

stsadm -o setproperty -propertyname max-template-document-size -propertyvalue 262144000  (250 MB)

The above STSADM sets the property at farm level. Here the command line takes property value in bytes. Technically SharePoint compresses all content and saves with .stp extension, which can be simply renamed to .cab and extracted.

SharePoint 2010 list template size limit:
In SharePoint 2010 and in SharePoint 2013, list template size limit has been raised to 50MB by default.
sharepoint list template maximum size
If you have a document library or list or site with content more than 50MB and when you try to save list as a template including content, by going to list settings >>"Save document library as template", you get this error message: "The list is too large to save as a template. The size of a template cannot exceed 524288000 bytes."
sharepoint 2010 list template maximum size
SharePoint 2013 version's Error message:
sharepoint 2013 site template maximum size


Same old stsadm can help to increase the template size limit in both SharePoint 2010 and 2013.

Using PowerShell to Get/Set SharePoint list template maximum size:
Its also possible to use PowerShell. Here is an example of setting SharePoint 2010 list / site template maximum size:
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

#For MOSS 2007, Uncomment below two lines
#[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
#[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Administration")

$webservice = [Microsoft.SharePoint.Administration.SPWebService]::ContentService

#Get the current Maximum Size
$webservice.MaxTemplateDocumentSize 

#Set New Limit and update
$webservice.MaxTemplateDocumentSize = 524288000 #500 MB
$webservice.Update()
  
Although the maximum template size in SharePoint 2010 or in SharePoint 2013 can be set to: 524288000 (500 MB), Always try to keep it in lower than: 50 MB for better performance!


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Delete List Template in SharePoint using PowerShell

Here is how to delete SharePoint list templates using PowerShell script:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Variables for Site URL and List template name
$SiteURL="http://intranet.crescent.com/sites/sales/"
$ListTemplateName ="Project Health.stp"

#Get Site and List Template Folder objects
$site = Get-SPSite $SiteURL
$ListTemplateFolder = $site.RootWeb.GetFolder("_catalogs/lt")

#Find the Specific List template and delete
$ListTemplate = $ListTemplateFolder.Files | Where-Object { $_.Name -eq $ListTemplateName }

if($ListTemplate)
 {
    $ListTemplate.Recycle()
    #To permanently delete, call: $ListTemplate.delete();
    write-output "Deleted List template!" 
 }


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Saturday, February 1, 2014

Copy Attachment from SharePoint List to Document Library using SharePoint Designer - PowerShell

SharePoint keeps attachments under "List >> Attachments >> 'List Item ID'" folder path. So, if you want to copy attachment from list to document library, follow these steps:
  1. Open your SharePoint site from SharePoint Designer
  2. Navigate to "All Files" view >> Lists >> Your Source List >> Attachments folder. Here, folders are created based on list item's ID. 
    sharepoint copy attachment from list to document library
  3. Just copy attachment files from these folders and navigate to the target document library and paste there.sharepoint designer 2010 copy attachment
Well, it would be tedious to copy list attachment to document library, if you have large number of list items/attachments. So, lets use PowerShell in SharePoint to copy list attachment to document library.


PowerShell script to copy attachment from list to document library:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$WebURL = "http://sharepoint.crescent.com/pmo/GIS/"

$SourceListName = "External Projects"   
$TargetLibraryName = "Design Documents"

#Get the Web List and Library objects
$web = Get-SPWeb $WebURL
$SourceList = $web.Lists[$SourceListName]    
$TargetLibrary = $web.Lists[$TargetLibraryName]    

#Loop through each list item
foreach ($ListItem in $SourceList.Items)
  {
 if($ListItem.Attachments.Count -gt 0)
         {
  #Loop through each attachment in the list item
        foreach ($Attachment in $ListItem.Attachments)    
         {   
    #Get the attachment
              $file = $web.GetFile($ListItem.Attachments.UrlPrefix+$Attachment)        
              $bytes = $file.OpenBinary()               
    
    $TargetFileName = $TargetLibrary.RootFolder.Url+"/"+$Attachment
    $TargetFile = $TargetLibrary.RootFolder.Files.Add($TargetFileName, $bytes, $true)
    Write-Host "Copied to: $($TargetFilename)"
   }
  }
 }
This script copies all attachments from all list items to the given library's root folder. You can tweak the script little to create sub-folders in the target library too.

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Server Status Remains "Upgrade Available" Even After Installing Latest Patches

Recently, We patched one of our SharePoint 2013 environment and ran SharePoint products configuration wizard without any issues. However, we noticed that the server status is still in "Upgrade Available" for SharePoint application & Web front end server from Central Administration > System Settings > Manage servers in this farm page. Ideally the server status should read "No action required" if everything goes good.

The "Upgrade available" simply means that there is a newer patch available at the SharePoint Updates page than the one installed on your SharePoint farm. We checked the Farm version and made sure its the latest available version.

Tried: psconfig -cmd upgrade -inplace b2b -wait and then restarted servers. Made sure windows updates are up to date on these servers.

Solution:
Found this issue is related to either some of the content databases/sites which still needs upgrade!

Run: stsadm -o localupgradestatus  from any of your server stating the "Upgrade Available" status. You should get a summary like:

[5] content database(s) encountered.
[1] content database(s) still need upgrade or cannot be upgraded.
[10] site collection(s) are contained in the content databases.
[4] site collection(s) still need upgrade.
[53] other objects encountered, [0] of them still need upgrade or cannot be upgraded.

Based on the summary, you have to either upgrade your SharePoint database or sites (Upgrade-SPContentDatabase, Upgrade-SPSite). Once done with your site or database upgrade, run PSConfig wizard again.

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Create Service Application Proxy Group in SharePoint 2013 using PowerShell

SharePoint Proxy groups associates service application proxies with Web Applications. By default, SharePoint creates a proxy group called "Default" and adds new service applications to "Default Proxy Group" when created via SharePoint central administration. A Service Application Proxy can be associated with multiple Proxy Groups using PowerShell. Similarly, a Proxy Group is NOT required to host all available Service Applications within the farm.

You can get the available proxy groups by going to Central Admin >> Application Management >> Manage Web Applications >> Select any web application and click on "Service Connections" from the ribbon.
sharepoint 2010 create proxy group powershell

While creating Service applications through PowerShell, You have to explicitly specify "-DefaultProxyGroup" switch to add the service application proxy to default group.
New-SPStateServiceDatabase -Name "StateServiceDB" -DatabaseServer 
$databaseServerName | New-SPStateServiceApplication -Name $stateSAName |
 New-SPStateServiceApplicationProxy -Name "$stateSAName Proxy" 
-DefaultProxyGroup 

Manage Proxy Group in SharePoint 2013 using PowerShell
There is no UI in SharePoint to create our own proxy group. So, Lets create a proxy group in SharePoint using PowerShell:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Get all proxy groups
Get-SPServiceApplicationProxyGroup  | Format-Table -Wrap
Create Proxy Group in SharePoint 2013 using PowerShell
#Create new proxy group
 $NewProxyGroup = New-SPServiceApplicationProxyGroup -Name "Intranet Service Applications"
Add a service application proxy to new proxy group:
#Get an existing Proxy Group
$ProxyGroup = Get-SPServiceApplicationProxyGroup -Identity "Intranet Service Applications"

#Get an existing Service App proxy to add to New Proxy group
$MMSProxy = Get-SPServiceApplicationProxy | ? { $_.DisplayName -eq "Hosting Farm Tenant Managed Metadata Service Proxy"}
#Add new member to new Proxy group
Add-SPServiceApplicationProxyGroupMember -identity $NewProxyGroup -Member $MMSProxy
Add all available service application proxies to New Proxy group in SharePoint 2010 using PowerShell
#Add All existing Service App proxies to New Proxy group
Get-SPServiceApplicationProxy | ForEach-Object { Add-SPServiceApplicationProxyGroupMember -identity $NewProxyGroup -Member $_ }
How to remove a member from Proxy Group
#To Remove Proxy group member
Remove-SPServiceApplicationProxyGroupMember -Identity $NewProxyGroup -Member $MMSProxy
Remove a Proxy Group in SharePoint using PowerShell
#Remove a Group Group
Remove-SPServiceApplicationProxyGroup -Identity "Intranet Service Applications" 
Here is the screenshot of new proxy group created:
sharepoint 2013 create proxy group PowerShell



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


How to Delete a SharePoint List using PowerShell

Problem: A faulty solution installed on the SharePoint farm created duplicate lists in all sites in a large site collection with 100+ sites in it. We had to remove them all!

To delete a list from SharePoint, from the browser, we can go to: View All Site Content >> Click on "Remove" link from the context menu of the list. Alternatively, You can get into List Settings >> click on "Delete this list" to remove a list in SharePoint.
delete list from sharepoint powershell
However, There are 100+ sites where a particular list needs to be deleted.

Solution: Delete SharePoint list using PowerShell
PowerShell command to delete list in SharePoint:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Site collection URL 
$SiteUrl="http://your-sharepoint-site" 
$ListName = "List-Name-To-Delete"

#Get Web and List objects
$web = Get-SPWeb $SiteURL
$list = $web.Lists[$ListName]

#Reset the "Allow Deletion" Flag
$list.AllowDeletion = $true
$list.Update()

$list.Delete()

write-host "List has been deleted successfully!"

One liner to delete a SharePoint list using PowerShell:
Get-SPWeb "http://Your-Site-URL" | Where-Object { $_.Lists.Delete([System.Guid]$_.Lists["Your-List-Name"].ID) }

SharePoint 2010 PowerShell delete list by GUID
Get-SPWeb "http://your-SharePoint-Site-URL" | Where-Object { $_.Lists.Delete([System.Guid]"{43c30f3a-f39a-4410-976c-a87bebb36e42}") }
Just replace the Web URL and GUID with yours and run the script.

Lets make a custom function to delete SharePoint list using PowerShell script.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Custom function to delete SharePoint list or document library using powershell
Function Delete-SPList
{
    param
    (
        [string]$WebURL  = $(throw "Please Enter the Web URL!"),
        [string]$ListName = $(throw "Please Enter the List Name to Delete!")
    )
    
    #Get the Objects 
    $Web = Get-SPWeb $WebURL
    $List = $Web.lists[$ListName]
 
    if($List)
    {
        #Set Allow Delete Flag
        $list.AllowDeletion = $true
        $list.Update()

        #delete list from sharepoint using powershell - Send List to Recycle bin
        $list.Recycle()
        
        #TO permanently delete a list, Use: 
        #$List.Delete()

        Write-Host "List: $($ListName) deleted successfully from: $($WebURL)"
    }
    else
    {
        Write-Host "List: $($ListName) doesn't exist at $($WebURL)"
    }
    $web.Dispose() 
}

#Call the function to delete list
Delete-SPList "http://intranet.crescent.com" "ConfigListv1"

So, call the function by looping through sites:
#Site URL variable
$SiteURL ="http://intranet.crescent.com" 

#get the site collection
$Site = Get-SPSite $SiteURL

#Loop through each site in the site collection
Foreach($web in $site.Allwebs)
{
    #Call the function to delete list
    Delete-SPList $web.URL "ConfigListv1"
}

Force delete delete corrupt SharePoint list using PowerShell:
In some cases, you need PowerShell's help when you are unable to delete list from SharePoint web UI as the list is corrupted and SharePoint won't let you to remove it, Use this script to remove SharePoint list using PowerShell: Force delete corrupted list in SharePoint using PowerShell

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


You might also like:

Related Posts Plugin for WordPress, Blogger...