Public/Get-IISVersion.ps1
Function Get-IISVersion { <# .Synopsis Find version of Internet Information Services installed. .Description Reads version of Internet Information Services installed from registry. Works only on Server OS'ses .Parameter Computername The Computername .Example PS C:\> Get-IISVersion Version PSComputerName RunspaceId ------- -------------- ---------- 10 Computer01 30a72116-430b-4d4d-83c0-6e3e0285755b .Inputs None .LINK about_functions_advanced .LINK about_CommonParameters #> [CmdletBinding()] [OutputType('JBOAPPLS.IIS.Version.Information')] Param ( [Parameter()] [Alias('CN', 'Name', 'Computer')] [string]$ComputerName = "localhost", [Parameter()] [System.Management.Automation.PSCredential]$Credential ) Begin { If (-not $PSBoundParameters.ContainsKey('Verbose')) { $VerbosePreference = $PSCmdlet.SessionState.PSVariable.GetValue('VerbosePreference') } If (-not $PSBoundParameters.ContainsKey('ErrorAction')) { $ErrorActionPreference = $PSCmdlet.SessionState.PSVariable.GetValue('ErrorActionPreference') } } Process { Foreach ($Computer in $ComputerName) { Write-Verbose ('{0}:: Retrieving data from {1}' -f $MyInvocation.MyCommand, $Computer) $session = New-PSSession @PSBoundParameters Invoke-Command -Session $session -ScriptBlock { Try { If (Get-Module -Name ServerManager -ErrorAction SilentlyContinue) { $webserver = Get-WindowsFeature Web-Server If ($webserver.Installed -eq "True") { Write-Verbose ('{0}:: Collecting data from {1}' -f $MyInvocation.MyCommand, $Computer) $MajorVersion = (Get-ItemProperty HKLM:\SOFTWARE\Microsoft\InetStp\).MajorVersion $properties = @{ PSTypeName = 'JBOAPPLS.IIS.Version.Information' Version = $MajorVersion } $obj = New-Object -TypeName psobject -Property $properties Write-Output $obj } } Else { Throw "ServerManager module is required but cannot be loaded" } } Catch { $properties = @{ PSTypeName = 'JBOAPPLS.IIS.Version.Information' Version = $null } $obj = New-Object -TypeName psobject -Property $properties Write-Output $obj } } } } End { } } |