
Journal Sylver Dragon's Journal: Powershell
So, I beat up Microsoft a bit in the comments of my last post about mmc and Office (the latter being started by tqft, but I was right there with him). So, I thought I would turn it around for a bit and give MS some props for something they did very right: Powershell.
I love me some Powershell, in that hot monkey, using the I/O ports for what god never intended, kind of way. I'm a keyboard junkie, always have been. And I still have a habit of using the command line to do tasks which MS put in a GUI long ago(net use beats the piss out of Tools - Map Network Drive). That's not to say that I hate GUI's, I just find the command line to work better in most cases. Though, the funny thing on this is that I hate config files, I like GUI's for program configuration. My typing skills are actually crap, and I hate having to hunt through a few hundred lines of:
hFetchSomethingWhichIGaveAReallyLongNameToButStillMeansNothingToSomeoneWhoIsNotACSMajor = 5
Because I typed a 'r' instead of an 'e'.
Ok, it's not that bad, but configuring Apache feels like a puzzle in the Tomb of Horrors some days. Granted, MS has a bad habit of jamming everything in the registry and having no easy way to look at it. stsadm.exe is useful for all sorts of things; like actually making Sharepoint not take a shit on you. However, unless you read MSDN compulsively, you may not know that, in order to configure the "no shitting on me" setting of sharepoint you need to run:
stsadm -o please -NotShitOnMe -url http://www.diaf.666
Unless, of course, you installed Project Server first, in which case the command changes into three different commands having to do with sand, Vaseline and a barrel.
But, Powershell...Yes, now this is a small slice of sanity on Windows. Honestly, they just ripped off a good idea from the *nix world, but what the hell, I'll take it. Powershell, for those who haven't tried it, is essentially a DOS command interpreter with direct access to the .Net API, with a bunch of pre-made applications on top. It's the command interpreter on steroids. Just what the IT guy with not enough to do and too much time needs. (And if I ever meet that bastard I am going to kill him and take his job.)
One of my habits is scripting. Pretty much, if it takes more than three steps and I am going to have to do it more than three times, you can expect me to turn out a script for it. Powershell makes this far, far easier. Most of what can be done in PS can be done in VBS. Actually, I imagine it all can. But, if I have to futz around with one more callback function, I am going to shoot someone. I'm not a programmer. If I was a programmer I would be spending my days attending meetings, creating design docs and reading use cases; might actually write some code in there too. No, I chose IT. I spend my days attending meetings, creating system reports and posting on Slashdot. Every once in a while I do actually work on systems, but ideally, that should only happen in a planned fashion. Also, I have a tech working with me, so I can foist most of the real work on him anyway.
Amazingly enough, my most recent use of Powershell actually was for writing reports. There is something kind of sad about writing a report with a script, but hey, it's what ya gotta do. We're doing an audit at my work and we needed to profile all of our servers. Name, IP, OS, Service Tag (We use Dell almost exclusively) and all installed software and versions. I did this all by hand last year and it was three levels of suck. So, this year I set out to automate the process. The way I figure it, the computers already have all of that information, and the profile doc is a known format; why not just make the computer do it. That is what they are good at, storing data and performing repetitive tasks. So, having been playing with PS for a while (we run Exchange 2007, which means I've played with PS) I decided that it would be perfect for the task.
Sure, VBS would have gotten there, but it would have been a mess. I know, I've done some VBS in the past, and it wasn't pretty. Well, a few hours later, I had a nice chunk of powershell script churning out beautifully formatted (actually, the format is crap, but it's THE format) server profiles. Just point the script at an OU in the Active Directory tree, and it profiles all of the servers in there.
The other recent use was in setting up students. The program I support gets a new raft of students every six months. Each student needs an account, a mailbox, a user folder, a web folder and an ftp folder, and all the various permissions which go along with those, plus email and security groups, and don't forget to sort the students and their computers into the appropriate OU in AD. It's such loads of fun, and after the 10th student or so, I usually miss something somewhere. So, I figured this time around, why in the hell am I doing this by hand? I know I'm going to screw something up, script it! Fire up trusty Crimson Editor (there is a powershell language file for it), and get typing. The end result is a script which, when pointed at a .csv file with first and last names, and given a group number creates all of the AD objects, folders, groups, etc. Basically, it does an hour or two of work for me, which has lots of potential for mistakes, into 30 seconds of watching the script spit out feedback.
One of these days, I'm probably going to try using Visual Studio to write this stuff too. Having played with VB enough, and C# a bit, I know how useful intelli-crack can be. I just hate having to wait for a few minutes for it to come up to change one line of a script. Much the same reason I bitch about the Management Studio in MSSQL 2005, I've actually had to wait longer for the damn thing to come up than it took me to type and run the command I wanted to do. I miss isqlw.exe.
Well, this has gone on long enough. So, for all the other Windows Admins out there, let me give a positive recommendation for Windows PowerShell. MS actually got this one right. (blind squirrels, broken clocks and all)
I love me some Powershell, in that hot monkey, using the I/O ports for what god never intended, kind of way. I'm a keyboard junkie, always have been. And I still have a habit of using the command line to do tasks which MS put in a GUI long ago(net use beats the piss out of Tools - Map Network Drive). That's not to say that I hate GUI's, I just find the command line to work better in most cases. Though, the funny thing on this is that I hate config files, I like GUI's for program configuration. My typing skills are actually crap, and I hate having to hunt through a few hundred lines of:
hFetchSomethingWhichIGaveAReallyLongNameToButStillMeansNothingToSomeoneWhoIsNotACSMajor = 5
Because I typed a 'r' instead of an 'e'.
Ok, it's not that bad, but configuring Apache feels like a puzzle in the Tomb of Horrors some days. Granted, MS has a bad habit of jamming everything in the registry and having no easy way to look at it. stsadm.exe is useful for all sorts of things; like actually making Sharepoint not take a shit on you. However, unless you read MSDN compulsively, you may not know that, in order to configure the "no shitting on me" setting of sharepoint you need to run:
stsadm -o please -NotShitOnMe -url http://www.diaf.666
Unless, of course, you installed Project Server first, in which case the command changes into three different commands having to do with sand, Vaseline and a barrel.
But, Powershell...Yes, now this is a small slice of sanity on Windows. Honestly, they just ripped off a good idea from the *nix world, but what the hell, I'll take it. Powershell, for those who haven't tried it, is essentially a DOS command interpreter with direct access to the
One of my habits is scripting. Pretty much, if it takes more than three steps and I am going to have to do it more than three times, you can expect me to turn out a script for it. Powershell makes this far, far easier. Most of what can be done in PS can be done in VBS. Actually, I imagine it all can. But, if I have to futz around with one more callback function, I am going to shoot someone. I'm not a programmer. If I was a programmer I would be spending my days attending meetings, creating design docs and reading use cases; might actually write some code in there too. No, I chose IT. I spend my days attending meetings, creating system reports and posting on Slashdot. Every once in a while I do actually work on systems, but ideally, that should only happen in a planned fashion. Also, I have a tech working with me, so I can foist most of the real work on him anyway.
Amazingly enough, my most recent use of Powershell actually was for writing reports. There is something kind of sad about writing a report with a script, but hey, it's what ya gotta do. We're doing an audit at my work and we needed to profile all of our servers. Name, IP, OS, Service Tag (We use Dell almost exclusively) and all installed software and versions. I did this all by hand last year and it was three levels of suck. So, this year I set out to automate the process. The way I figure it, the computers already have all of that information, and the profile doc is a known format; why not just make the computer do it. That is what they are good at, storing data and performing repetitive tasks. So, having been playing with PS for a while (we run Exchange 2007, which means I've played with PS) I decided that it would be perfect for the task.
Sure, VBS would have gotten there, but it would have been a mess. I know, I've done some VBS in the past, and it wasn't pretty. Well, a few hours later, I had a nice chunk of powershell script churning out beautifully formatted (actually, the format is crap, but it's THE format) server profiles. Just point the script at an OU in the Active Directory tree, and it profiles all of the servers in there.
The other recent use was in setting up students. The program I support gets a new raft of students every six months. Each student needs an account, a mailbox, a user folder, a web folder and an ftp folder, and all the various permissions which go along with those, plus email and security groups, and don't forget to sort the students and their computers into the appropriate OU in AD. It's such loads of fun, and after the 10th student or so, I usually miss something somewhere. So, I figured this time around, why in the hell am I doing this by hand? I know I'm going to screw something up, script it! Fire up trusty Crimson Editor (there is a powershell language file for it), and get typing. The end result is a script which, when pointed at a
One of these days, I'm probably going to try using Visual Studio to write this stuff too. Having played with VB enough, and C# a bit, I know how useful intelli-crack can be. I just hate having to wait for a few minutes for it to come up to change one line of a script. Much the same reason I bitch about the Management Studio in MSSQL 2005, I've actually had to wait longer for the damn thing to come up than it took me to type and run the command I wanted to do. I miss isqlw.exe.
Well, this has gone on long enough. So, for all the other Windows Admins out there, let me give a positive recommendation for Windows PowerShell. MS actually got this one right. (blind squirrels, broken clocks and all)
Powershell More Login
Powershell
Slashdot Top Deals