Powershell Tips Series Part 2 : Get details of orphans in Content DB and Timer job history by date and time range in SharePoint 2010


Sriram Varadarajan
Enterprise Architect
Published On :   03 Oct 2015
Visit Count
Today :  1    Total :   7765
Plan, Migrate, Secure, Report
SharePoint & Office 365 Tool. Simple & Easy to Use. 15-Day Trial!

Sharegate: Kick-Ass Tool
Think Your SharePoint & Office 365 Are Secure ? Find Out Now!


As a continuations of PowerShell script series, in this blog post , the first script enables to find orphans in SharePoint and the second script helps to find out the timer job history for a specified date and time range in SharePoint 2010

Detecting Orphans for the content DB in sharepoint 2010:

 $LogTime = Get-Date -Format yyyy-MM-dd_hh-mm
 $LogFile = ".\FindOrphanSitesPatch-$LogTime.txt"
 
 if ((Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) 
 {Add-PSSnapin Microsoft.SharePoint.Powershell}
  
 $dbs = Get-SPContentDatabase
 start-transcript $logfile
 ForEach ($db in $dbs)
 {
     Write-Host “Detecting Orphans for the content DB: ” $db.name 
      
     $db.repair($false)
 }
 stop-transcript
 ########### end of script ################################################
 

 

Retrieve timer job history for a specified time range in sharepoint 2010:

 # Retrieve timer job history for a specified time range
 # Initial settings 
 Add-pssnapin Microsoft.SharePoint.Powershell
 $Wa = Get-SPWebApplication "https://XXX.am.XXX.com"    # Supply the web app url here 
 $From= "8/24/2015 02:00:00 AM"  # mm/dd/yyyy hh:mm:ss 
 $To = "8/24/2015 04:00:00 AM"
 
 # Retrieve all jobs in the time range 
 Write-Host "Listing all timer jobs that have run between $From to $To and storing it in CSV format" -ForeGroundColor Blue 
 $Wa.JobHistoryEntries | Where-Object {($_.StartTime -gt $From) -and ($_.StartTime -lt $To)} | Export-Csv TimerJobHistory.csv –NoType
 
 Write-Host "Done.." -ForeGroundColor Green
 
 # Retrieve all failed jobs in the time range 
 Write-Host "Listing all timer jobs that have failed to run between $From to $To and storing it in CSV format" -ForeGroundColor Red 
 $Wa.JobHistoryEntries | Where-Object {($_.StartTime -gt $From) -and ($_.To -lt $To) -and ($_.Status -ne 'Succeeded')} | Export-Csv FailedTimerJobHistory.csv –NoType
 
 Write-Host "Done.." -ForeGroundColor Green
 
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Categories

KWizCom Forms App