The Microsoft Scripting Guys'2010 Scripting Games
is in full swing, and I've been perusing the entries.
One of my favorites so far
is in the advanced division, and is designed to set a registry key on one or more remote computers. The author notes, however, that "I'm unhappy with this solution... IMO this script needs a -credential parameter, but I couldn't get alternate credentials working across platforms( xp,vista,w7)... So I settled on the .net alternative."
It's a great script, because it uses many of the killer new features in PowerShell v2: Comment-based help, script cmdlets (called "advanced functions"), and so on. One new v2 feature the author could have relied on, however, is remoting and the Invoke-Command cmdlet. With that cmdlet, all of the .NET mucking about with the registry could be eliminated: You could simply write a command that used PowerShell's HKCU: or HKLM: drive, transmit that command to the remote computer via Invoke-Command, and have the command execute locally. Invoke-Command supports a -credential parameter, so you'd get alternate credential action, too. True, going that route would entail that remoting be enabled - but in the context of the Scripting Games that's a fine pre-req, and I think shops are going to be enabling remoting pretty broadly before long, anyway.
Invoke-Command is awesome because it eliminates the need to build your own "remote access" solution, or to try and dig up a built-in way to access something remotely. You can simply use whatever command runs locally, and ship it off to the remote computers.
I'm excited to see what else the Scripting Games brings!