Functions/Private/Artifacts/AllWindowsFeatures/Discover_AllWindowsFeatures.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
function Discover_AllWindowsFeatures {
<#
.SYNOPSIS
Scans for presence of DHCP Server component in a Windows Server image.
 
.PARAMETER MountPath
The path where the Windows image was mounted to.
 
.PARAMETER OutputPath
The filesystem path where the discovery manifest will be emitted.
#>

[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess",'')]
[CmdletBinding()]
param (
    [Parameter(Mandatory = $true)]
    [string] $MountPath,
    [Parameter(Mandatory = $true)]
    [string] $OutputPath
)

$ArtifactName = Split-Path -Path $PSScriptRoot -Leaf
Write-Verbose -Message ('Started discovering {0} artifact' -f $ArtifactName)

$Manifest = '{0}\{1}.json' -f $OutputPath, $ArtifactName

$WindowsFeatures = Get-WindowsOptionalFeature -Path $MountPath | Where-Object State -EQ Enabled

$ManifestResult = @{
    FeatureName = ''
    Status = ''
}
$DefaultEnabledFeatures = (Get-Content $PSScriptRoot\DefaultFeatures.txt).Split(';')
$EnabledFeatures = New-Object System.Collections.ArrayList

$wind
foreach ($WindowsFeature in $WindowsFeatures) {
     if ($DefaultEnabledFeatures -notcontains $WindowsFeature.FeatureName) {
            $EnabledFeatures.Add($WindowsFeature.FeatureName) | Out-Null 
        }
    }

$ManifestResult.FeatureName = $EnabledFeatures -join ';'
$ManifestResult.Status = 'Enabled'   
### Write the result to the manifest file
$ManifestResult | ConvertTo-Json | Set-Content -Path $Manifest

Write-Verbose -Message ('Finished discovering {0} artifact' -f $ArtifactName)
}