Created
March 19, 2021 07:18
-
-
Save pronichkin/209d4236b6919a567fec4bfd788acf13 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function | |
Get-WindowsPackageEx | |
{ | |
[System.Management.Automation.CmdletBindingAttribute()] | |
Param( | |
[System.Management.Automation.ParameterAttribute( | |
Mandatory = $True, | |
ParameterSetName = 'Online' | |
)] | |
[System.Management.Automation.SwitchParameter] | |
$Online | |
, | |
[System.Management.Automation.ParameterAttribute( | |
Mandatory = $True, | |
ParameterSetName = 'Offline' | |
)] | |
[System.IO.DirectoryInfo] | |
$Path | |
, | |
[System.Management.Automation.ParameterAttribute()] | |
[Microsoft.Dism.Commands.ReleaseType] | |
$Type | |
, | |
[System.Management.Automation.ParameterAttribute()] | |
[System.Management.Automation.ValidateSetAttribute( | |
'Cumulative operating system update', | |
'Cumulative .Net Framework update', | |
'Servicing stack update', | |
'Experience feature pack', | |
'Language pack', | |
'Language feature', | |
'Foundation', | |
'Feature on demand', | |
'Other' | |
)] | |
[System.String] | |
$Filter | |
, | |
[System.Management.Automation.ParameterAttribute()] | |
[Microsoft.Dism.Commands.PackageFeatureState] | |
$State | |
) | |
Process | |
{ | |
switch | |
( | |
$psVersionTable.psEdition | |
) | |
{ | |
'Core' | |
{ | |
throw 'Unfortunately DISM cmdlets are not compatible with PowerShell (Core)' | |
} | |
'Desktop' | |
{ | |
$PackageParam = @{ | |
'Verbose' = $False | |
} | |
switch | |
( | |
$Filter | |
) | |
{ | |
'Cumulative operating system update' | |
{ | |
$Name = 'Package_for_RollupFix*' | |
} | |
'Cumulative .Net Framework update' | |
{ | |
$Name = 'Package_for_DotNetRollup*' | |
} | |
'Servicing stack update' | |
{ | |
$Name = 'Package_for_ServicingStack*' | |
} | |
'Experience Feature Pack' | |
{ | |
$Name = 'Package_for_WindowsExperienceFeaturePack*' | |
} | |
'Language Pack' | |
{ | |
$Name = '*LanguagePack*' | |
} | |
'Language Feature' | |
{ | |
$Name = '*LanguageFeatures*' | |
} | |
'Foundation' | |
{ | |
$Name = 'Microsoft-Windows-Foundation-Package*' | |
} | |
'Feature on demand' | |
{ | |
$Name = '*FoD-Package*' | |
} | |
'Other' | |
{ | |
$Name = 'Package_for_KB*' | |
} | |
Default | |
{ | |
$Name = '*' | |
} | |
} | |
$PackageParam.Add( 'PackageName', $Name ) | |
switch | |
( | |
$psCmdlet.ParameterSetName | |
) | |
{ | |
'Online' | |
{ | |
$PackageParam.Add( 'Online', $True ) | |
} | |
'Offline' | |
{ | |
$PackageParam.Add( 'Path', $Path.FullName ) | |
} | |
} | |
[System.Collections.Generic.List[ | |
Microsoft.Dism.Commands.AdvancedPackageObject | |
]] $Package = [System.Collections.Generic.List[ | |
Microsoft.Dism.Commands.AdvancedPackageObject | |
]]::new() | |
Get-WindowsPackage @PackageParam | ForEach-Object -Process { | |
$Package.Add( $psItem ) | |
} | |
if | |
( | |
$Type | |
) | |
{ | |
$Package = $Package | Where-Object -FilterScript { | |
$psItem.ReleaseType -eq $Type | |
} | |
} | |
if | |
( | |
$State | |
) | |
{ | |
$Package = $Package | Where-Object -FilterScript { | |
$psItem.PackageState -eq $State | |
} | |
} | |
return $Package | |
} | |
Default | |
{ | |
throw 'Unknown PowerShell edition' | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment