Checking Operating System

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Lery Lery 3 years, 9 months ago.

  • Author
    Posts
  • #8138
    Profile photo of Lery
    Lery
    Participant

    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?

  • #8139
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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.

  • #8148
    Profile photo of Lery
    Lery
    Participant

    [quote=8139]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. [/quote]

    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.

You must be logged in to reply to this topic.