Created
June 26, 2014 21:34
-
-
Save mbourgon/833d1b0194136676eb9b to your computer and use it in GitHub Desktop.
RSS checker for SQL Release Services Blog (aka SQL Server patch release notifications) (powershell portion, 1/2)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Script downloads an rss feed of data about SQL Server service packs and cummulative updates. | |
.DESCRIPTION | |
Script downloads data into a staging table and is called by a job. | |
.PARAMETER <paramName> | |
There are no parameters. | |
.EXAMPLE | |
Call from a job: powershell "& 'C:\Powershell_Scripts\rss_feed_SqlServer_Releases.ps1'" | |
#> | |
# CREATE TABLE SQL_Server_Releases_from_RSS_stg | |
#( | |
# title varchar(200), | |
# link varchar(500), | |
# pubdate smalldatetime, | |
# descr varchar(MAX) --short for "description" but avoids using the key word | |
#) | |
. C:\Powershell_Scripts\out-datatable.ps1 #Chad Miller rocks! | |
. C:\Powershell_Scripts\write-datatable.ps1 | |
. C:\Powershell_Scripts\add-sqltable.ps1 | |
try | |
{ | |
#Get the rss feed and save in the staging table | |
[xml]$rss = Invoke-WebRequest http://blogs.msdn.com/sqlreleaseservices/rss.xml | |
$datatable = $rss.rss.channel.item | select title, link, @{Name="pubdate";Expression={get-date ($_.pubdate) -format "yyyy/MM/dd hh:mm"}}, @{Name="descr";Expression={$_."Description"}} |out-datatable | |
write-datatable -ServerInstance "sql_repository" -Database dba_rep -TableName SQL_Server_Releases_from_RSS_stg -data $datatable | |
#Run the stored procedure that updates the permanent table from the staging table and sends an email if anything is updated | |
$svr = "yourservernamehere" | |
$cnn = New-Object System.Data.SqlClient.SqlConnection("Server=yourservernamehere; Initial Catalog=yourrepositorynamehere; Integrated Security=SSPI") | |
$cmd = New-Object system.Data.SqlClient.SqlCommand | |
$cmd.CommandType = [System.Data.CommandType]::StoredProcedure | |
$cmd.CommandText = "SqlServer_Releases_Update" | |
$cmd.Connection = $cnn | |
$cnn.Open() | |
$cmd.ExecuteNonQuery() | |
$cnn.Close() | |
} | |
catch | |
{ | |
write-host "Caught an exception:" -ForegroundColor Red | |
write-host "Exception Type: $($_.Exception.GetType().FullName)" -ForegroundColor Red | |
write-host "Exception Message: $($_.Exception.Message)" -ForegroundColor Red | |
throw $_.Exception.Message | |
exit 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment