I have a requirement to check the Windows operating system that my script will be running on. Â If the operating system is Windows Server 2008, the script needs to check to see if the ISE is installed. Â Ultimately this is because my script utilizes out-gridview. Â The problem is introduced because Windows 7 SP1 and Windows Server 2008 use the same build number. Â It looks like the product type field is a good thing to key off of. Â So if I run: Â (gwmi win32_operatingsystem).producttype I get back 1 for Windows 7 and 3 for any flavor of Windows Server 2008. Â Does that sound OK to you all, or should I key off a different field?
MS uses that field for client vs. server. I’d use the Version field, which is text. It’s longer, but more specific. But that’s just me.
You could also just ignore that and check to see if powershell_ise.exe exists. In Win7 it always should. But, it only takes a microsecond to check and see if a file exists, and it should always be in the folder held in $pshome.
I mean, if you just check for the file… then you only get one check on a client or a server. If you check the version andÂ then the file, you get 1 or 2 checks, right? Seems easier to just check for the file.
That said… goodness, I hope your organization isn’t making a habit of relying on GUI components on the server OS. That’s definitely a 1990s approach. I’dÂ much rather see scripts output pure objects if they find themselves running on a server. That way the output can be easily captured to a file. You’re notÂ supposed to be logging onto the server and watching GridViews pop up :). That’s why the ISE isn’t installed on them by default. As you move into Win2012 and beyond, you’re going to be increasingly less likely to have the option of having a GUI on the server, so now might be a good time to think about how you’ll deal with that, before you make too much more investment in Out-GridView.
I mean… if a script outputs objects, then you could schedule that to run and dump objects to CliXML on a server. It’s easy to import that XML and pipe to a GridView from your client computer, when you want to review the results. Anyway… just give it some thought. Creating server dependencies on GUI is going to create pain for you later, I promise.
Thanks for the response Don. Â I checked the version field on Windows 7 SP1 and Windows 2008 R2 server, and they’re the same. Â Both come in at 6.1.7601. Â However, I love the idea of checking for powershell_ise.exe. Â I will use that method going forward.
It’s not my choice about using the GUI on the server. Â In fact I’ve advised against it. Â Unfortunately the folks that have a few more zeros on their paycheck made that foolish decision.