Showing posts with label 2010. Show all posts
Showing posts with label 2010. Show all posts

Monday, February 9, 2015

Use PowerShell to Delete SharePoint List Items Based on Parameters From an External File

Below is a PS script I wrote to take parameters from a .csv file, find matching SharePoint list items based on 2 parameters, and delete that list item. I am also writing to another external .txt file the parameters of any list items that were missed so I can investigate why there was no match (internal administration).

#Import the csv file that holds the parameters we need to filter the SharePoint
$csv = Import-Csv d:\temp\importfilename.csv

#An error file - Clear this file in case anything was there from a previous run Clear-Content d:\temp\checkTheseFailedDeletes.txt

#Get the SharePoint web(site)
$web = Get-SPWeb http://sharepointsite

#Get the SharePoint list
$list = $web.Lists["Your List Name Here"]

$itemsTotal = 0
$count = 0

#Loop through each row of the input .csv file
foreach ($rox in $csv)
{
     #Assign each column's value to a variable
     $thisParam1 = $row.Param1ColumnFromCSV
     $thisParam2 = $row.Param2ColumnFromCSV

     #Build the CAML query and execute it on the list
     $query = New-Object Microsoft.SharePoint.SPQuery
     $query.ViewAttributes = "Scope='Recursive'"
     $caml = "$thisParam1$thisParam2"
     $query.Query = $caml
     $items = $list.GetItems($query)

     #Delete the item from the list if found
     if ($items.Count -gt 0)
     {
          $items | % { list.GetItemById($_.Id).Delete() }
          $caml = ""
          $count++
     }
    
     #Write records that were not found in the list to a text file to manually check if necessary
     else
     {
          $caml = ""
          $writeString = $thisParam1 + ", " + $thisParam2
          Add-Content d:\temp\checkTheseFailedDeletes.txt $writeString
     }
    
     $itemsTotal++
}

Write-Host $itemsTotal "records processed ===> " $count "records deleted"
$web.Dispose()

Tuesday, May 21, 2013

Resolving a HTTP/1.1 200 OK Server: Microsoft-IIS/7.5 Error with a SharePoint 2010 Web Application

My team ran into this error on a SharePoint site during a disaster recovery drill while testing after failover and failback:

HTTP/1.1 200 OK Server: Microsoft-IIS/7.5 Connection: close

We have load balanced WFEs so we determined the offending WFE and temporarily manually routed traffic to the good WFE.  Obviously, this is not the desired solution but it worked as a temporary solution to get through the DR drill.

To resolve this issue permanently, we tried detaching and reattaching the content database for the Web Application and, success!  Mad props go out to Mark Rhodes for his post, Resolving a HTTP/1.1 200 OK Server: Microsoft-IIS/7.5 Error with a SharePoint 2010 Web Application, on this same issue.  Thank you, sir!