Freigeben über


PowerShell で RSS フィードを作成する方法

??? Visual Studio 2008 ReadyDay ??????Visual Studio 2008 ? .NET Framework 3.5 ???????????????????????????? RSS ???????????????.NET Framework 3.5 ??????????

System.ServiceModel.Syndication ????

https://msdn2.microsoft.com/
ja-jp/library/system.servicemodel.syndication.aspx

WCF ??? .NET Framework 3.5 ????? HTTP ???????

https://msdn.microsoft.com/msdnmag/issues/
08/01/WCFinOrcas/default.aspx?loc=jp

Windows PowerShell ?? XML ??????????????RSS ??????????????????????????????????????????????????????????????????

????????

 [Reflection.Assembly]::LoadWithPartialName("System.ServiceModel.Web") | Out-Null
$sss = "System.ServiceModel.Syndication."

?????????????????????(??????????????????Out-Null ?????????)System.ServiceModel.Web.dll ????????.NET Framework 3.5 (??????????) ???????????????????????????????System.ServiceModel.Syndication ????????????????????????????????????????????????????????????????????

 $feed = new-object ($sss + "SyndicationFeed")
$feed.Title = "Event Logs"
$feed.LastUpdatedTime = [DateTimeOffset]::Now

???????????????????????? SyndicationFeed (MSDN ?????) ???????????????????????? RSS ???????????????????????

????????????????????????????????? RSS ??????????????????

 Get-EventLog System -Newest 100 | `
foreach {
  $item = new-object ($sss + "SyndicationItem")
  $item.Title = "[{0}] {1}: {2}" -f $_.Index, $_.EntryType, $_.Source
  $item.Authors.Add((new-object ($sss + "SyndicationPerson") `
                         ($_.Source + "@" + $_.MachineName), $null, $null))
  $item.Categories.Add((new-object ($sss + "SyndicationCategory") $_.EntryType))
  $item.Categories.Add((new-object ($sss + "SyndicationCategory") $_.EventID))
  $item.Categories.Add((new-object ($sss + "SyndicationCategory") $_.Source))
  $item.PublishDate = $_.TimeGenerated
  $item.Content = new-object ($sss + "TextSyndicationContent") $_.Message
  $feed.items.add($item)
}

???Get-EventLog ?????????????????100????????????`???????????????????

???????????????????foreach ?1????????????????????????????????????????? SyndicationItem (MSDN ?????) ???SyndicationItem ???????????????????????????

Title ?????????????????????? (EventRecordID) ????·????????????????????????????????????????????????????????????

Authors ??????????????????????????????????????????????

Categories ?????????????????????????????????????·ID·??????????????????

PublishDate ??????????Content ??????????????????????????????????????????? Items ????????????

?????????????????

 $rssFormatter = new-object ($sss + "Rss20FeedFormatter") $feed
$rssFile = "c:\inetpub\wwwroot\logrss\rsstest.xml"
$rssWriter = [System.Xml.XmlWriter]::Create($rssFile)
$rssFormatter.WriteTo($rssWriter);
$rssWriter.close()

Rss20FeedFormatter ??? (MSDN ?????) ???? RSS 2.0 ??????????Atom10FeedFormatter ??? (MSDN ?????) ?????Atom 1.0 ??????????

???????????????? IIS ??????????? rsstest.xml ???????? IIS ??????????????????????????????????? [Console]::Out ??????????????????????????????????????????????????

?? Internet Explorer ?? https://localhost/logrss/rsstest.xml ???????????????????????????

Event Log Feed

?????????????????????????????????ID·???·????????????????????????????? DHCP ??????????????

Event Log RSS Filtered

??????PowerShell ??? .NET Framework 3.5 ??????? SyndicationFeed ??????XML ??????????? RSS ??????????????????????????????? RSS ??????????????????????????????????????????????????????????????