Monday, September 13, 2010

Subscribing to RSS Feeds

Using the Microsoft.FeedsManager we can easily subscribe to RSS feeds:

$fm = New-Object -ComObject Microsoft.FeedsManager

Lets look at the properties:








We want to work with RootFolder:











FeedFolder.CreateFeed(name,url)

Creates feed in folder and subscribes to it. Lets test it out by subscribing to my blog:

$fm.RootFolder.CreateFeed("Get-Command","http://get-command.blogspot.com/feeds/posts/default")


Now lets have some fun, for those who follow @ScriptingGuys recently they have been
sharing links to popular PowerShell blogs, here is how you can subscribe to,
if not all, most of them



$PoshURLs = @{
"Development in a Blink" = "http://feeds.feedburner.com/DevelopmentInABlink";
"Get-PowerShell" = "http://get-powershell.com/feed/";
"get-powershellblog" = "http://marcoshaw.blogspot.com/rss.xml";
"Huddled Masses" = "http://huddledmasses.org/feed/";
"Jonathan Medds Blog" = "http://www.jonathanmedd.net/feed";
"jonoble Blog" = "http://www.jonoble.com/blog/rss.xml";
"Nivot Ink" = "http://www.nivot.org/SyndicationService.asmx/GetRss";
"out-web.net" = "http://feeds.feedburner.com/Out-webnet";
"PowerScripting Podcast" = "http://feeds.feedburner.com/Powerscripting";
"PowerShell Script Repository" = "http://poshcode.org/feed";
"PowerShell with a Purpose" = "http://feeds.feedburner.com/winblog/pspurpose";
"PowerShell.CA" = "http://www.energizedtech.com/atom.xml";
"PowerShell.com" = "http://powershell.com/cs/blogs/MainFeed.aspx";
"Richard Siddaways Blog" = "http://richardsiddaway.spaces.live.com/feed.rss";
"Shay Levy" = "http://feeds.feedburner.com/ShayLevy";
"TechProsaic" = "http://feeds.feedburner.com/halr9000";
"The PowerShell Guy" = "http://thepowershellguy.com/blogs/posh/rss.aspx";
"Windows PowerShell Blog" = "http://blogs.msdn.com/powershell/rss.xml"
}

$PoshURLs.GetEnumerator() | % {$fm.RootFolder.CreateFeed($_.Name,$_.Value)}

Friday, September 10, 2010

Simple timed while loop

A simple way of executing a while loop over a certain amount of time:



$now = Get-Date
$later = $now.AddSeconds(15)

while($now.second -lt $later.second){

cls
$now = Get-Date
$now.second
sleep 1

}

Tuesday, August 31, 2010

Finding the string you need

I use this simple one liner a lot whenever I need to find code that needs to be changed in multiple scripts. I often find myself having to update anywhere from 1 to 80 automated test scripts. This one liner will give me the name of the script and the line number of the string I'm looking for.



# Using select-string

select-string -pattern "get-command" -path "C:\Scripts\*.ps1" | foreach-Object{Write-Host $_.FileName, $_.linenumber}


Monday, August 30, 2010

Awww my first post

So I wanted a function that I could use to find/replace text in multiple files in a directory with a recursive option, and this is what I came up with. I had help from another blog post, but cant remember the author)

function Update-Content($find, $replace, $path, [switch]$Recurse)
{
if($Recurse){
get-childitem $path -Recurse | select-string $find -list |% { (get-content $_.Path) |% { $_ -replace $find, $replace } | set-content $_.Path }
}
else{
get-childitem $path | select-string $find -list |% { (get-content $_.Path) |% { $_ -replace $find, $replace } | set-content $_.Path }
}
}