Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By : Donabel Santos
Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By: Donabel Santos

Overview of this book

Table of Contents (21 chapters)
SQL Server 2014 with PowerShell v5 Cookbook
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Creating an RSS feed from SQL Server content


In this recipe, we will create an RSS feed from SQL Server content.

Getting ready

For this recipe, we will use a simple query to populate our RSS feed. We will list our database list from sys.databases and use it as fictional content for our RSS file.

How to do it...

These are the steps required to create an RSS feed using T-SQL and PowerShell:

  1. Open PowerShell ISE as an administrator.

  2. Import the SQLPS module as follows:

    #import SQL Server module
    Import-Module SQLPS -DisableNameChecking
  3. Add the following script and run it:

    $instanceName = "localhost"
    $databaseName = "SampleDB"
    $timestamp = Get-Date -format "yyyy-MMM-dd-hhmmtt"
    $rssFileName = "C:\XML Files\rss_$timestamp.xml"
    
    #values to be used for RSS
    $rssTitle = "QueryWorks Latest News"
    $rssLink = "http://www.queryworks.ca/rss.xml"
    $rssDescription = "What's new in the world of QueryWorks"
    
    #use r as date formatter to get
    #date in RFC1123Pattern
    $rssDate = (Get-Date -Format r)
    $rssManagingEditor = "info...