Sweet candelabra of La Habra, LaBarbara!

PS Joshua:\> Get-HermesQuote
Sacred hog of Prague!
PS Joshua:\> Get-HermesQuote
Sweet gorilla of Manila!
PS Joshua:\> Get-HermesQuote
Sweet lamprey of Santa Fe!
PS Joshua:\> Get-HermesQuote
Sweet bongo of the Congo!
PS Joshua:\> Get-HermesQuote
Sweet dodo of Lesotho!
PS Joshua:\> Get-HermesQuote
Sweet kookaburra of Edinburgh!
PS Joshua:\> Get-HermesQuote
Sweet bongo of the Congo!
PS Joshua:\> Get-HermesQuote
Sweet lamprey of Santa Fe!


Lets have some fun using the method “split” and Get-Random:
When creating a text array we distinguish between different items in the array by separating them with commas as seen here:

PS Joshua:\> $TextArray = "Alpha", "Bravo", "Charlie", "Delta", "Echo"
PS Joshua:\> $TextArray
Alpha
Bravo
Charlie
Delta
Echo
PS Joshua:\> $TextArray.count
5

But what if we want to turn multiple lines of text into an array?

PS Joshua:\> $MultiLineText = @"
Alpha
Bravo
Charlie
Delta
Echo
"@
PS Joshua:\> $MultiLineText
Alpha
Bravo
Charlie
Delta
Echo
PS Joshua:\> $MultiLineText.count
1

Notice how the count is 1 not 5? That’s because PowerShell is treating the multiple lines of¬ text as a single object.¬ In order to turn the single object into an array of objects we need to use the “Split” method:

PS Joshua:\> $MultiLineText.Count
1
PS Joshua:\> $MultiLineTextArray = $MultiLineText.Split("`n")
PS Joshua:\> $MultiLineTextArray.Count
5

You can see that the Splitting the object at the new line character “`n” we are able to create an array of objects. Once we have an array we can address the objects individually:

PS Joshua:\> $MultiLineTextArray[2]
Charlie
PS Joshua:\> $MultiLineTextArray[0]
Alpha
PS Joshua:\> $MultiLineTextArray | Get-Random
Delta
PS Joshua:\> $MultiLineTextArray | Get-Random
Bravo
PS Joshua:\> $MultiLineTextArray | Where-Object {$_ -ne "Charlie"}
Alpha
Bravo
Delta
Echo

With this knowledge we can have some fun with Quotes from our old friend Hermes, here’s my full code for getting randomized Quotes:

Function Get-HermesQuote{            
(            
@"
Sweet lion of Zion!
Sweet manatee of Galilee!
Sweet llamas of the Bahamas!
Sweet gorilla of Manila!
Sweet something... of... someplace...!
Great cow of Moscow!
Sweet giant anteater of Santa Anita!
Sweet lamprey of Santa Fe!
Sweet ghost of Babylon!
Sacred boa of West and Eastern Samoa!
Sacred hog of Prague!
Cursed bacteria of Liberia!
Sweet guinea pig of Winnipeg!
Great bonda of Uganda!
Sweet three-toed sloth of the ice planet Hoth!
Sweet honey bee of infinity!
Sweet yeti of the Serengeti!
Sweet bongo of the Congo!
Sweet squid of Madrid!
Sweet kookaburra of Edinburgh!
Sweet topology of cosmology!
Sweet coincidence of Port-au-Prince!
Sweet Georgia Brown of Kingston Town!
Sweet dodo of Lesotho!
File not found of Puget Sound!
Sweet Tornadoes of Barbados!
Sweet candelabra of La Habra, LaBarbara!
Sweet ego of Montego!
Sweet freak of Mozambique!
"@            
).Split("`n")|Get-Random            
}