Write-StickyNote

Here’s a fun script that uses the new “Sticky Notes” in WIndows 7.

The script is based on a simple function that uses the SendKeys() method through the Wscript.Shell COM object. This is a nice example on how you can handle COM objects through PowerShell.

I’ve also included an if statement that checks if StickyNotes is active. If that’s the case, the text will be started in a new StickyNotes.. note..

Anyway, here’s the function.


function Write-StickyNote ([string]$Text) {

	if (gps | Where { $_.ProcessName -match "stikynot" }) {

		$StickyNote = $True
	}

	$Wscript = New-Object -Com Wscript.Shell
	[void]$Wscript.Run("stikynot.exe")
	start-sleep 1

	if ($StickyNote -eq $True) {

		$Wscript.SendKeys("^n")	
	}

	$Wscript.SendKeys($Text)
}

And here’s an example on running the function.


PS > .\Write-StickyNote.ps1 "Hello from PowerShell.nu"

stickynotes01

Click here to download the Script

Rating 3.50 out of 5
[?]

RSS, Speech and PowerShell

Rss Feeds are great ways of keeping track of updates and news on pages that you frequently visit. In this post we are going to look at an alternative way of examining Rss Feeds. We will use Net.WebClient .Net Class to access the Feed through PowerShell and store the information in a PsCustomObject. Finally we will use SPVoice Com object to read the HeadLines.

We Connect to the Rss Feed through Net.WebClient


PS > $WebClient = New-Object Net.WebClient
PS > $DownloadString = $WebClient.DownloadString("http://www.powershell.nu/feed/rss/")

Now that we have downloaded the information from the Feed we can start analyzing and modifying it. Starting off, we want to grab all Urls that link to the Posts. We can accomplish this through the Select-String CmdLet.


PS > $rss = $DownloadString.Split() | select-string -case "<link>" 

It might also be a good idea to remove unwanted data. We can use the -replace operator to do this.


PS > $rss = $rss -replace ".*<link>",""
PS > $rss = $rss -replace "</link>.*",""

If we look at the $rss object it contains the Urls to all recent blog posts.


PS > $rss


http://www.powershell.nu


http://www.powershell.nu/2009/03/15/insert-a-page-break-in-a-word-document-using-powershell/


http://www.powershell.nu/2009/03/15/sharepoint-and-powershell-in-real-life/


http://www.powershell.nu/2009/03/09/create-site-with-approval-workflow-using-powershell-part-2/


http://www.powershell.nu/2009/03/08/set-themeps1-set-theme-in-sharepoint-using-powershell/


http://www.powershell.nu/2009/03/08/the-scandinavia-powershell-user-group/

Now that we have all the Urls, we can loop through each of them and get additional information from the posts. Im going to get retrieve the Title and som Text describing the Post. Im also adding a if statement to omit the default index page. you can check out the function in the Complete script.

Now that we know how to retrieve information from Rss Feeds and Internet sites we can continue and check out the SAPI.SPVoice Com object.


function Rss-Read ([string]$speechy) {

	$SPVoice = New-Object -Com SAPI.SPVoice
	$SPVoice.Speak($speechy) | Out-Null
}

typing Rss-Read followed by some text will trigger the Com object to read the argument.

Last part is putting it all togheter. I do this through a third function that calls on the other functions.


function Get-News {

	$Rss = Get-Rss

	$Rss | ForEach {

		$_ | Format-List

		Rss-Read $_.HeadLine
	}
}

And here’s a link to the complete Script

Examples on Running the Script:


PS > .\Rss-Read.ps1

PS > .\Rss-Read.ps1 -help

Rating 3.00 out of 5
[?]