Improve performance of Package identification

Using -ListAvailable with Get-Command to ensure no module loading is
    attampeted while querying loaded commands.
    This improved performance when certain modules have not been
    loaded yet
This commit is contained in:
Gal Szkolnik 2021-04-27 16:04:12 +00:00
parent 499a86baa6
commit 22aa3ba435
10 changed files with 17 additions and 17 deletions

View file

@ -23,7 +23,7 @@ class Packagesz { #: System.Management.Automation.IValidateSetValuesGenerator {
$local:valid = $Package.Condition[0].Logic -notin ([szLogic]::or, [szLogic]::ornot)
$local:currentSys = [SystemName]::_GetValidValues('',$true,$true);
$local:hostname = $(hostname)
$local:allCmdlets = Get-Command | Select-Object -ExpandProperty Name
$local:allCmdlets = Get-Command -ListImported | Select-Object -ExpandProperty Name
$local:username = $( if( $env:USER ) { $env:USER } else { $env:USERNAME } )
@ -45,7 +45,7 @@ class Packagesz { #: System.Management.Automation.IValidateSetValuesGenerator {
}
if( $v -and $c.AppExeExists ) {
$v = $v -and -not $($c.AppExeExists | Where-Object {
-not ( Get-Command $_ -Type Application -ErrorAction SilentlyContinue )
-not ( Get-Command -ListImported $_ -Type Application -ErrorAction SilentlyContinue )
})
}
if( $v -and $c.custom ) {