Sha256: 33f4d8a0940c0ba99a7a040031bf463b168ee0c5589b1f92cf125c7f86bba1d3

Contents?: true

Size: 1.91 KB

Versions: 464

Compression:

Stored size: 1.91 KB

Contents

function ListWindowsFeatures
{    

param(
        [string]$feature,
        [string]$provider="dism"
         )

    $cachepath =  "${env:temp}/ListWindowsFeatures-${provider}.xml"
    $maxAge = 2

    $cache =  Get-Item $cachepath -erroraction SilentlyContinue

    if($cache -ne $null -and ((get-date) - $cache.LastWriteTime).minutes -lt $maxage){
        $features = Import-Clixml $cachepath |  Select *| Where-Object {(($_.name -like $feature) -or ($_.displayName -like $feature)) -and (($_.installed -eq $true) -or ($_.state -eq "Enabled"))}
        return $features
    }
    else{

        switch($provider)
        {
            "dism" { return features_dism | Select * | Where-Object {($_.name -eq $feature) -and ($_.state -eq "Enabled")}  }
            "powershell" { return features_powershell | Select * | Where-Object {(($_.name -like $feature) -or ($_.displayName -like $feature)) -and ($_.installed -eq $true)} }
            default {throw "Unsupported provider"}
        }

    }
}

function features_dism{
      try
        {
            $out = DISM /Online /Get-Features /Format:List | Where-Object {$_}     

            if($LASTEXITCODE -ne 0)
            {
                Write-Error $out
                Break
            }

            $f = $out[4..($out.length-2)]
            $features = for($i=0; $i -lt $f.length;$i+=2)
            {
                $tmp = $f[$i],$f[$i+1] -replace '^([^:]+:\s)'
                
                New-Object PSObject -Property @{
                    Name = $tmp[0]
                    State = $tmp[1]
                }
            }

            $features | Export-Clixml $cachepath

            return $features
        }
        catch
        {
            Throw
        }
}

function features_powershell{
    $ProgressPreference = "SilentlyContinue"
     import-module servermanager
     $features = Get-WindowsFeature
     $features | Export-Clixml $cachepath
     return Get-WindowsFeature 
}

Version data entries

464 entries across 464 versions & 3 rubygems

Version Path
specinfra-2.91.0 lib/specinfra/backend/powershell/support/list_windows_features.ps1
specinfra-2.90.1 lib/specinfra/backend/powershell/support/list_windows_features.ps1
specinfra-2.90.0 lib/specinfra/backend/powershell/support/list_windows_features.ps1
specinfra-2.89.0 lib/specinfra/backend/powershell/support/list_windows_features.ps1
specinfra-2.88.2 lib/specinfra/backend/powershell/support/list_windows_features.ps1
specinfra-2.88.1 lib/specinfra/backend/powershell/support/list_windows_features.ps1
specinfra-2.88.0 lib/specinfra/backend/powershell/support/list_windows_features.ps1
specinfra-2.87.2 lib/specinfra/backend/powershell/support/list_windows_features.ps1
specinfra-2.87.1 lib/specinfra/backend/powershell/support/list_windows_features.ps1
specinfra-2.87.0 lib/specinfra/backend/powershell/support/list_windows_features.ps1
specinfra-2.86.0 lib/specinfra/backend/powershell/support/list_windows_features.ps1
specinfra-2.85.1 lib/specinfra/backend/powershell/support/list_windows_features.ps1
specinfra-2.85.0 lib/specinfra/backend/powershell/support/list_windows_features.ps1
specinfra-2.84.1 lib/specinfra/backend/powershell/support/list_windows_features.ps1
specinfra-2.84.0 lib/specinfra/backend/powershell/support/list_windows_features.ps1
specinfra-2.83.4 lib/specinfra/backend/powershell/support/list_windows_features.ps1
specinfra-2.83.3 lib/specinfra/backend/powershell/support/list_windows_features.ps1
specinfra-2.83.2 lib/specinfra/backend/powershell/support/list_windows_features.ps1
specinfra-2.83.1 lib/specinfra/backend/powershell/support/list_windows_features.ps1
specinfra-2.83.0 lib/specinfra/backend/powershell/support/list_windows_features.ps1