24

I wish to find the version of IIS using a powershell (or WMI) query.

The following is the query which I have used.

Get-WmiObject -namespace "root\microsoftiisv2" -query "select MajorIIsVersionNumber from IISWebInfo"

I tested this query using powershell console in a 'Windows 8' PC with 'IIS 8'. But the result is 7 , where the expected version Number is 8.

Can someone help me to solve this issue?.

Kiquenet
  • 14,494
  • 35
  • 148
  • 243
Sebastian Xavier
  • 2,499
  • 7
  • 27
  • 41
  • The answers to this question might help: ["How to determine installed IIS version"](http://stackoverflow.com/questions/435050/how-to-determine-installed-iis-version) – Enrico Campidoglio May 28 '13 at 11:42

5 Answers5

31

You can try:

get-itemproperty HKLM:\SOFTWARE\Microsoft\InetStp\  | select setupstring,versionstring 
CB.
  • 58,865
  • 9
  • 159
  • 159
  • This will give correct answer, But It would be great if there is a WMI or Powershell query for the same. – Sebastian Xavier May 29 '13 at 05:36
  • @user1805353 I'm sorry but I'm not aware for other methods, maybe the powershell 'webadministration' module can help. – CB. May 29 '13 at 10:40
  • 1
    This is not reliable because it can return values on servers that do not have IIS installed. Whether or not they once had IIS on, I can't confirm just yet, but I can definitely confirm IIS is not running / installed on some machines that have this reg key. – Robin Oct 15 '14 at 12:31
  • 1
    @Rob, @ CB. , Besides that, is there an **official source** from Microsoft that states `HKLM:\SOFTWARE\Microsoft\InetStp\VersionString` is the way to get the version? Otherwise, such reverse engineering might seriously break in the future when the keys/values are changed... – Pacerier Aug 14 '15 at 05:24
  • I'm looking for servers without IIS installed. So before I get-itemproperty I check if the item exist first. gci HKLM:\SOFTWARE\Microsoft | ?{$_.Name -match 'InetStp'} – Kirt Carson Oct 27 '15 at 19:48
7

Even though the thread is little old,this is the link I landed first. So letting you know what I found.

The below command helped me find the IIS version correctly on IIS 8.5 (Windows 2012 R2) and 7.5 Windows 7 SP1.

[System.Diagnostics.FileVersionInfo]::GetVersionInfo("$env:SystemRoot\system32\inetsrv\InetMgr.exe").ProductVersion

Reference:

https://forums.iis.net/p/1171695/1984536.aspx : Answer from f00_beard

3

If you want the decimal value for order comparison.

$iisInfo = Get-ItemProperty HKLM:\SOFTWARE\Microsoft\InetStp\
$version = [decimal]"$($iisInfo.MajorVersion).$($iisInfo.MinorVersion)"
Andy McCluggage
  • 37,618
  • 18
  • 59
  • 69
  • 1
    Honestly, I think this should use the `[version]` type instead of decimal. If there was a version 10.10 it would be less than version 10.2 if a decimal type was used. – arjabbar Apr 26 '17 at 17:34
1

Here's a little ScriptBlock function that I created based on the answer from @C.B. to get the IIS Version from a remote computer.

$pwd = convertto-securestring "yourstrongpasswordhere" -asplaintext -force
$cred=new-object -typename System.Management.Automation.PSCredential -argumentlist "machinenamehere\adminusernamehere",$pwd

$iisversion= Invoke-Command -ComputerName $machineName -ScriptBlock { 

    $(get-itemproperty HKLM:\SOFTWARE\Microsoft\InetStp\).setupstring

} -Credential $cred

Write-Host iisversion = $iisversion
If($iisversion -like '*IIS 6*'){
    Write-Host This server uses IIS6
}

If($iisversion -like '*IIS 7*'){
    Write-Host This server uses IIS7
}
Adrian Carr
  • 3,061
  • 1
  • 34
  • 38
0

For purely the version, I prefer checking the info on the w3wp executable. Per the "how-to" article from MSFT:

    If(Test-Path $w3wpPath) { 
        $productProperty = Get-ItemProperty -Path $w3wpPath 
        Write-Host $productProperty.VersionInfo.ProductVersion 
    } 
    Else { 
        Write-Host "Not find IIS." 
    } 
Strake
  • 702
  • 1
  • 8
  • 18