Skip to content
This repository was archived by the owner on Mar 11, 2020. It is now read-only.

Commit 68304c5

Browse files
author
Mano Marks
authored
Merge pull request #36 from sixeyed/master
Add Windows Server 2008 support for IIS
2 parents c660cf3 + 90b49a5 commit 68304c5

16 files changed

+167
-60
lines changed

Functions/Private/Artifacts/AddRemovePrograms/Discover_AddRemovePrograms.ps1

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@ The filesystem path where the discovery manifest will be emitted.
1414
param (
1515
[Parameter(Mandatory = $true)]
1616
[string] $MountPath,
17+
18+
[Parameter(Mandatory = $true)]
19+
[string] $OutputPath,
20+
1721
[Parameter(Mandatory = $true)]
18-
[string] $OutputPath
22+
[string] $ImageWindowsVersion,
23+
24+
[Parameter(Mandatory = $false)]
25+
[string[]] $ArtifactParam
1926
)
2027

2128
$ArtifactName = Split-Path -Path $PSScriptRoot -Leaf
@@ -33,7 +40,7 @@ $RegistryMount = @{
3340
ArgumentList = 'load "HKLM\{0}" "{1}\Windows\System32\Config\SOFTWARE"' -f $TempKey, $MountPath
3441
Wait = $true
3542
}
36-
Start-Process @RegistryMount
43+
Start-Process @RegistryMount -WindowStyle Hidden
3744
Write-Verbose -Message ('Finished loading the SOFTWARE registry hive from {0}' -f $MountPath)
3845

3946
### Define empty array to hold installed software items
@@ -60,7 +67,7 @@ $RegistryUnmount = @{
6067
ArgumentList = 'unload "HKLM\{0}"' -f $TempKey
6168
Wait = $true
6269
}
63-
Start-Process @RegistryUnmount
70+
Start-Process @RegistryUnmount -WindowStyle Hidden
6471
Write-Verbose -Message 'Finished unmounting the registry hive'
6572

6673
### Write out the discovery results to the manifest file

Functions/Private/Artifacts/AllWindowsFeatures/Discover_AllWindowsFeatures.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@ The filesystem path where the discovery manifest will be emitted.
1414
param (
1515
[Parameter(Mandatory = $true)]
1616
[string] $MountPath,
17+
18+
[Parameter(Mandatory = $true)]
19+
[string] $OutputPath,
20+
1721
[Parameter(Mandatory = $true)]
18-
[string] $OutputPath
22+
[string] $ImageWindowsVersion,
23+
24+
[Parameter(Mandatory = $false)]
25+
[string[]] $ArtifactParam
1926
)
2027

2128
$ArtifactName = Split-Path -Path $PSScriptRoot -Leaf

Functions/Private/Artifacts/Apache/Discover_Apache.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@ The filesystem path where the discovery manifest will be emitted.
1414
param (
1515
[Parameter(Mandatory = $true)]
1616
[string] $MountPath,
17+
18+
[Parameter(Mandatory = $true)]
19+
[string] $OutputPath,
20+
1721
[Parameter(Mandatory = $true)]
18-
[string] $OutputPath
22+
[string] $ImageWindowsVersion,
23+
24+
[Parameter(Mandatory = $false)]
25+
[string[]] $ArtifactParam
1926
)
2027

2128
$ArtifactName = Split-Path -Path $PSScriptRoot -Leaf

Functions/Private/Artifacts/DHCPServer/Discover_DHCPServer.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@ The filesystem path where the discovery manifest will be emitted.
1414
param (
1515
[Parameter(Mandatory = $true)]
1616
[string] $MountPath,
17+
18+
[Parameter(Mandatory = $true)]
19+
[string] $OutputPath,
20+
1721
[Parameter(Mandatory = $true)]
18-
[string] $OutputPath
22+
[string] $ImageWindowsVersion,
23+
24+
[Parameter(Mandatory = $false)]
25+
[string[]] $ArtifactParam
1926
)
2027

2128
$ArtifactName = Split-Path -Path $PSScriptRoot -Leaf

Functions/Private/Artifacts/DNSServer/Discover_DNSServer.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@ The filesystem path where the discovery manifest will be emitted.
1414
param (
1515
[Parameter(Mandatory = $true)]
1616
[string] $MountPath,
17+
18+
[Parameter(Mandatory = $true)]
19+
[string] $OutputPath,
20+
1721
[Parameter(Mandatory = $true)]
18-
[string] $OutputPath
22+
[string] $ImageWindowsVersion,
23+
24+
[Parameter(Mandatory = $false)]
25+
[string[]] $ArtifactParam
1926
)
2027

2128
$ArtifactName = Split-Path -Path $PSScriptRoot -Leaf

Functions/Private/Artifacts/IIS/Discover_IIS.ps1

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ param (
2121
[Parameter(Mandatory = $true)]
2222
[string] $OutputPath,
2323

24+
[Parameter(Mandatory = $true)]
25+
[string] $ImageWindowsVersion,
26+
2427
[Parameter(Mandatory = $false)]
2528
[string[]] $ArtifactParam
2629
)
@@ -37,12 +40,15 @@ $ManifestResult = @{
3740
Status = ''
3841
}
3942

40-
try {
41-
$WindowsFeatures = Get-WindowsOptionalFeature -Path $MountPath
42-
$ManifestResult = GetManifestFromApplicationHost -OutputPath $OutputPath -MountPath $Mount.Path -ArtifactParam $ArtifactParam
43+
# Windows 5.2 -> Server 2003; use MetaBase discovery for IIS 6:
44+
if ($ImageWindowsVersion -eq '5.2') {
45+
Write-Verbose -Message "Checking IIS MetaBase config for Windows Version: $ImageWindowsVersion"
46+
$ManifestResult = GetManifestFromMetabase -OutputPath $OutputPath -MountPath $Mount.Path -ImageWindowsVersion $ImageWindowsVersion -ArtifactParam $ArtifactParam
4347
}
44-
catch {
45-
$ManifestResult = GetManifestFromMetabase -OutputPath $OutputPath -MountPath $Mount.Path -ArtifactParam $ArtifactParam
48+
else {
49+
# Use Application Host discovery for IIS 7 onwards:
50+
Write-Verbose -Message "Checking IIS ApplicationHost config for Windows Version: $ImageWindowsVersion"
51+
$ManifestResult = GetManifestFromApplicationHost -OutputPath $OutputPath -MountPath $Mount.Path -ImageWindowsVersion $ImageWindowsVersion -ArtifactParam $ArtifactParam
4652
}
4753

4854
if ($ManifestResult.Status -eq 'Present'){

Functions/Private/Artifacts/IIS/GetManifestFromApplicationHost.ps1

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,24 @@ param (
2121
[Parameter(Mandatory = $true)]
2222
[string] $OutputPath,
2323

24+
[Parameter(Mandatory = $true)]
25+
[string] $ImageWindowsVersion,
26+
2427
[Parameter(Mandatory = $false)]
2528
[string[]] $ArtifactParam
2629
)
2730

2831
$ManifestResult = @{
2932
FeatureName = ''
30-
Status = ''
33+
Status = 'Absent'
34+
AspNetStatus = 'Absent'
3135
}
3236

33-
$WindowsFeatures = Get-WindowsOptionalFeature -Path $MountPath
34-
$IIS = $WindowsFeatures.Where{$_.FeatureName -eq 'IIS-WebServer'}
35-
$EnabledFeatures = $WindowsFeatures.Where{$_.State -eq 'Enabled'}
36-
$FeaturesToExport = $EnabledFeatures.Where{$_.FeatureName -match 'IIS'-or
37-
$_.FeatureName -match 'ASPNET' -or
38-
$_.FeatureName -match 'Asp-Net' -and
39-
$_.FeatureName -NotMatch 'Management'} | Sort-Object FeatureName | Select-Object -ExpandProperty FeatureName
37+
$ApplicationHostPath = "$MountPath\Windows\System32\inetsrv\config\applicationHost.config"
4038

41-
if ($IIS.State -eq 'Enabled') {
39+
if (Test-Path -Path $ApplicationHostPath) {
4240

43-
$IISConfig = [xml](Get-Content -Path $MountPath\Windows\System32\inetsrv\config\applicationHost.config)
41+
$IISConfig = [xml](Get-Content -Path $ApplicationHostPath)
4442

4543
$AllSites = $IISConfig | Select-Xml -XPath "//sites" | Select-Object -ExpandProperty Node
4644
$siteDefaults = $AllSites.siteDefaults
@@ -74,19 +72,38 @@ if ($IIS.State -eq 'Enabled') {
7472

7573
$DefaultHandlers = [xml](Get-Content $PSScriptRoot\DefaultHandlers.xml) | Select-Xml -XPath "//handlers" | Select-Object -ExpandProperty Node | Select-Object -ExpandProperty add
7674
$handlers = New-object System.Collections.ArrayList
77-
75+
76+
$AspNetInstalled = $false
7877
foreach ($Handler in $HandlerList) {
7978
if (-not $DefaultHandlers.name -match $handler.Name) {
8079

81-
$handlers.Add([PSCustomObject]@{
82-
Name = $Handler.name
83-
Path = $Handler.path
84-
Verb = $Handler.verb
85-
}) | Out-Null
80+
$handlers.Add([PSCustomObject]@{
81+
Name = $Handler.name
82+
Path = $Handler.path
83+
Verb = $Handler.verb
84+
}) | Out-Null
85+
}
86+
if ($Handler.path.Contains('.aspx')) {
87+
$AspNetInstalled = $true
88+
}
8689
}
87-
}
88-
Write-Verbose -Message 'IIS service is present on the system'
89-
$ManifestResult.FeatureName = $FeaturesToExport -join ';'
90+
91+
#feature selection not valid for 2008 and below:
92+
if ([decimal]$ImageWindowsVersion -gt 6.1) {
93+
$WindowsFeatures = Get-WindowsOptionalFeature -Path $Mount.Path
94+
$IIS = $WindowsFeatures.Where{$_.FeatureName -eq 'IIS-WebServer'}
95+
$EnabledFeatures = $WindowsFeatures.Where{$_.State -eq 'Enabled'}
96+
$FeaturesToExport = $EnabledFeatures.Where{$_.FeatureName -match 'IIS'-or
97+
$_.FeatureName -match 'ASPNET' -or
98+
$_.FeatureName -match 'Asp-Net' -and
99+
$_.FeatureName -NotMatch 'Management'} | Sort-Object FeatureName | Select-Object -ExpandProperty FeatureName
100+
101+
$ManifestResult.FeatureName = $FeaturesToExport -join ';'
102+
if ($ManifestResult.FeatureName -like '*ASPNET*' -or $ManifestResult.FeatureName -like '*Asp-Net*'){
103+
$AspNetInstalled = $true
104+
}
105+
}
106+
90107
$ManifestResult.Status = 'Present'
91108
$ManifestResult.Websites = $Websites
92109
$ManifestResult.ApplicationPools = $appPools
@@ -95,16 +112,9 @@ if ($IIS.State -eq 'Enabled') {
95112
$ManifestResult.ApplicationDefaults = $applicationDefaults
96113
$ManifestResult.VirtualDirectoryDefaults = $virtualDirectoryDefaults
97114

98-
if ($ManifestResult.FeatureName -like '*ASPNET*' -or $ManifestResult.FeatureName -like '*Asp-Net*'){
115+
if ($AspNetInstalled -eq $true){
99116
$ManifestResult.AspNetStatus = 'Present'
100-
}
101-
else {
102-
$ManifestResult.AspNetStatus = 'Absent'
103-
}
104-
}
105-
else {
106-
$ManifestResult.Status = 'Absent'
107-
$ManifestResult.AspNetStatus = 'Absent'
117+
}
108118
}
109119

110120
return $ManifestResult

Functions/Private/Artifacts/IIS/GetManifestFromMetabase.ps1

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@ param (
2121
[Parameter(Mandatory = $true)]
2222
[string] $OutputPath,
2323

24+
[Parameter(Mandatory = $true)]
25+
[string] $ImageWindowsVersion,
26+
2427
[Parameter(Mandatory = $false)]
2528
[string[]] $ArtifactParam
2629
)
2730

2831
$ManifestResult = @{
2932
FeatureName = ''
30-
Status = ''
33+
Status = 'Absent'
34+
AspNetStatus = 'Absent'
3135
}
3236

3337
$MetabasePath = "$MountPath\Windows\System32\inetsrv\MetaBase.xml"
@@ -87,13 +91,6 @@ if (Test-Path -Path $MetabasePath) {
8791
if ($AspNetInstalled -eq $true){
8892
$ManifestResult.AspNetStatus = 'Present'
8993
}
90-
else {
91-
$ManifestResult.AspNetStatus = 'Absent'
92-
}
93-
}
94-
else {
95-
$ManifestResult.Status = 'Absent'
96-
$ManifestResult.AspNetStatus = 'Absent'
9794
}
9895

9996
return $ManifestResult

Functions/Private/Artifacts/MSMQ/Discover_MSMQ.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@ The filesystem path where the discovery manifest will be emitted.
1414
param (
1515
[Parameter(Mandatory = $true)]
1616
[string] $MountPath,
17+
18+
[Parameter(Mandatory = $true)]
19+
[string] $OutputPath,
20+
1721
[Parameter(Mandatory = $true)]
18-
[string] $OutputPath
22+
[string] $ImageWindowsVersion,
23+
24+
[Parameter(Mandatory = $false)]
25+
[string[]] $ArtifactParam
1926
)
2027

2128
$ArtifactName = Split-Path -Path $PSScriptRoot -Leaf

Functions/Private/Artifacts/SQLServer/Discover_SQLServer.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@ The filesystem path where the discovery manifest will be emitted.
1414
param (
1515
[Parameter(Mandatory = $true)]
1616
[string] $MountPath,
17+
18+
[Parameter(Mandatory = $true)]
19+
[string] $OutputPath,
20+
1721
[Parameter(Mandatory = $true)]
18-
[string] $OutputPath
22+
[string] $ImageWindowsVersion,
23+
24+
[Parameter(Mandatory = $false)]
25+
[string[]] $ArtifactParam
1926
)
2027

2128
function GetSQLInstances {

0 commit comments

Comments
 (0)