Email The Total Numbers Of The Items In A List

…this post was published on 2013 September 18.

Starting from this question on Sharepoint Forum, the first step is to count the items

For this you should know your site’s URL and you List Name. The items number will be calculated in variable $list-items.

<# Count items in that list #>
   $my_web =Get-SPWeb “Site_collection_URL”
   $my_list= $my_lists | Where-Object { $_.title -match  “Your_List_name” }
   $list_items  = $my_list.ItemCount

Next, the script will send this value to your specific recipients

<# Send Email #>
   <# prepare de details #>
   $EmailFrom = “your@email.address”
   $EmailTo = destination@email.address@email.address
   $EmailSubject = “Number of items in list: “+$my_list
   $emailbody = ” This list contain “+$list_items+” items”
   $SMTPServer = “SMTP server address”
   <# send the results #>
   $mailmessage = New-Object
   $mailmessage.from = $emailfrom
   $mailmessage.Subject = $emailsubject
   $mailmessage.Body = $emailbody
   $mailmessage.IsBodyHTML = $true
   $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer)

If necessary, you should save these line in a .ps1 file and schedule it at specific time.

This entry was posted in email, Powershell, Sharepoint. Bookmark the permalink.