As I’ve been doing a heck of a lot of PowerShell scripting the past few weeks at work, I’ve come to re-appreciate the comfort of being able to work in a very bounded environment. Network/Systems/Security work is pretty damned unbounded, but when you work on a programming or scripting language, you don’t have to necessarily sweat the scope or mechanics because they’re created for you, for the most part. You deal with the basics, loops, variables, moving data around, manipulating data, reading and writing to objects, and so on. It’s like putting together a jigsaw puzzle; there’s something comforting in the ability to focus. Plus the immediate response/results of scripting are really nice.
I stayed away from scripting, and more appropriately, programming when I was in college and just out of college because I didn’t want to find myself being a kickass XYZ programmer and only a kickass XYZ programmer while languages A, B, and C flew by. Maybe in another life or a future career opportunity will open up a more dedicated scripting/web dev job opp. I think I could live with that, honestly. I think it would have to be a smaller company, though, rather than just being the builder of Function A in Large, Slow, Non-Creative Company.
Maybe that’s why every couple years I perform some deep rework on my web pages, or have an affinity towards scripting. Once you know the mechanics and syntax and keywords of a language, it is all downhill from there (at least for me, since the logic comes easy to me). Braindump Ruby on Rails into my head, and I could probably have a lot of fun with that language, as much as Neo with Kung-Fu.
Anyway, my PowerShell snippet today involves deleting services. Creating services is pretty easy in PS, but deleting them was left behind for WMI to pick up. And no reboot is required. (Unless you have a service open at the time you attempt to delete it, in which case Windows will hang on that and hold the service for deletion until you reboot…so make sure you’re not working in the service anywhere before you try to trash it.)
$service = gwmi win32_service | ? {$_.name -match "ServiceName"} $service.delete()
Since this is short, I tend to do this manually, and I try to always make sure $service returns the proper service by calling it once just before the delete. And you do this to remote computers by adding “-computer ‘computername'” before the pipe (and with double quotes instead of my grammatically correct singles).