Language PowerShell
Date: | 08/20/08 |
Author: | Halo_Four |
URL: | n/a |
Comments: | 1 |
Info: | http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx |
Score: | (3.00 in 12 votes) |
99..0 | add-member -pass ScriptMethod SingStanza { $b = [int]$args[0]; if($b -eq 0) { "No more bottles of beer" } else { "$b bottle$(if($b -ne 1) { 's' }) of beer" } } | add-member -pass ScriptProperty CurrentStanza { $this.SingStanza($this) } | add-member -pass ScriptProperty NextStanza { if($this -eq 0) { $this.SingStanza(99) } else { $this.SingStanza($this - 1) } } | add-member -pass ScriptProperty Action { if($this -eq 0) { "Go to the store and buy some more" } else { "Take one down and pass it around" } } | %{ "$($_.CurrentStanza) on the wall, $($_.CurrentStanza.ToLower())`n$($_.Action), $($_.NextStanza.ToLower()) on the wall" }
Download Source | Write Comment
Download Source | Write Comment
Add Comment
Please provide a value for the fields Name,
Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.
Please don't post large portions of code here! Use the form to submit new examples or updates instead!
Comments
Kryten said on 01/03/09 01:47:47
cls;99..0 | % -Begin { } -Process {
$line1 = " bottles of beer on the wall,";$line2 = " bottles of beer"
$line3 = "Take one down and pass it around,";$line4 = "No more bottles of beer"
if ($_ -ge 3 ) {"$_$line1$_$line2";"$line3`n$($_ -1)$line1" }
if ($_ -eq 2 ) {"2$line1 2$line2";"$line3`n1 bottle of beer on the wall"}
if ($_ -eq 1 ) {"1 bottle of beer on the wall, 1 bottle of beer"; "$line3 `
no more$line1 no more$line2"}} -End {"Go to the store and buy some more,";"99$line1"}