Read xml using PowerShell in SharePoint

In this article we are showing how to read XML file using PowerShell, this is a sample example based on this we can develop the PowerShell scripts with config XML file, without touching the code modify the XML config file and send the mail based on the config file requirement, maintain the XML file will be very good and easy.

Here is the sample XML file to read the PowerShell for sending mail with to and from address with Subject and SMTP server information.

 Read xml in PowerShell
Here is the PowerShell code reading the XML file and sending Mail.

Add-PSSnapin Microsoft.SharePoint.Powershell

[xml]$xmlfile = Get-Content D:\Reading.xml

 $EmailFrom = $xmlfile.mail.mailFrom
  $EmailTo = $xmlfile.mail.mailTo
 $EmailSubject = $xmlfile.mail.mailSubject
 $SMTPServer = $xmlfile.mail.SMTPRelay

$mailmessage = New-Object

$mailmessage.from = ($EmailFrom)


$mailmessage.Subject = $EmailSubject

$mailmessage.IsBodyHTML = $true

$SMTPClient = New-Object  Net.Mail.SmtpClient($SMTPServer) 


SharePoint Online Real Time Training Contact: JLAKSHMITULASI@GMAIL.COM

Lakshmi Tulasi Jasti

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment


Post a Comment