Recently, I came across a scenario where there is a list which contains visitors' information and the admin team wants to get an email of Visitors for the following day.
This can be easily achieved using Timer Job or CSOM (using scheduler). I tried to achieve this using Powershell and Task Scheduler.
Here is my list.


| Columns Names | Data Type |
| Date of Visit | Date and Time |
| Host | People |
| Name fo visitor | Single of Text |
| Company | Single of Text |
| License Plate Number | Single of Text |
Created a View and applied Today+1 filter on the "Date of Visit" column.
Here is the PowerShell script to fetch the list data
- Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
- $MyWeb = Get-SPWeb "http://WebApp/Web/"
- $MyList = $MyWeb.Lists["ListName"]
- $spQuery = New-Object Microsoft.SharePoint.SPQuery
- $camlQuery = '<Where><Eq><FieldRef Name="Date_x0020_of_x0020_visit"/><Value Type="DateTime"><Today OffsetDays="1"/></Value></Eq></Where>'
- $spQuery.Query = $camlQuery
- $spListItems = $MyList.GetItems($spQuery)
- Write-Host "Count: " $spListItems.Count
- if($spListItems.Count -gt 0)
- {
- $spListItems | foreach {
- $Name = $_["Host"].split('#')
- New-Object PSObject -Property @{
- "Host" = $Name[1]
- "Date of Visit"= $_["Date_x0020_of_x0020_visit"]
- "Name of Visitor" = $_["Name_x0020_of_x0020_vistor"]
- "Company" = $_["Company"]
- "Licence Plate Number" = $_["License_x0020_plate_x0020_number"]
- }
- } | Select-Object "Date of Visit", "Name of Visitor", "Company","Licence Plate Number", "Host" | Export-Csv -path 'D:\Reports\TodaysVisitors.csv' -NoTypeInformation
- }


Piyush AgarwalPosted Mar 8, 2018, 2:07 AM
This really helps... Sending emails using power shell can help in eliminating workflow issues alot.... Thanks for this
Sagar PardeshiPosted Oct 3, 2017, 1:15 AM
Good blog..sachin ..