Many built-in cmdlets take input from the pipe, but alternatively let you specify an input with the -InputObject parameter. An example is the Get-Member cmdlet.
I want to be able to do this with my own functions, but as far as I can tell, there is no built-in mechanism for this for using an specified parameter instead of the pipe.
[Updated]
Read on »
I really like the way that PowerShell handily formats pipeline objects when displaying them in the console, eg get-childitem in a file system directory returns a collection of file objects and the output is like the old DOS dir command.
Additionally, I really like the way that hashes behave like objects with named properties. For example:
$a=@{"name"="bob";"age"=42}
$a.name # outputs "bob"
$a.age # outputs 42
Unfortunately, if you have a list/array of hashes with the same keys, you cannot benefit from this built-in formatting. The output comes out in two columns, keyed Name and Value.
I want a way to have the properties of the hash be the keys and the values be the values associated with those keys.
Read on »
There are twothree ways I know of to make noises in PowerShell.
1. Simple and most boring: use the internal speaker’s beep.
write-host "`a`a`a"
2. Slightly better, use the .NET console beep. This plays A above middle C for one second.
[console]::beep(440,1000)
Both of the above are synchronous, ie, the script blocks until the sound has finished. Richy Rich is doing some interesting stuff with runspaces to do this asynchronously.
3. Lastly, you can play wav files. Sadly, only .wav files. No midi, mp3, mpeg4.. at least I couldn’t find anything in .net 2.
$file='C:\\WINDOWS\\Media\\Windows XP Startup.wav'
$sp = new-object Media.SoundPlayer ($file)
$sp.Load();
$sp.Play();
1..5 | % {
echo "la la"
sleep 1
}
This plays the wav asynchronously, so I feel should be used in a future version of psinvaders to get those authentic sounds.
So anyone know of a way to play midi files asynchronously in PowerShell with only a few lines of code?