-
-
Save eplord/ba1c4630bde783f3000e05e8be732751 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Find-Software { | |
[CmdletBinding()] | |
param ( | |
<# | |
The name, or part of a name, of a package. | |
Should be enough to get a unique match or the results will get really messy. | |
#> | |
[Parameter(Mandatory)] | |
[Alias('Name')] | |
[string[]] | |
$PackageName, | |
<# | |
One or more computer names. | |
#> | |
[Parameter(ValueFromPipeline, ValueFromPipelineByPropertyName)] | |
[string[]] | |
$ComputerName = $env:COMPUTERNAME, | |
<# | |
See Get-Help Invoke-Command. | |
#> | |
[Parameter()] | |
[int] | |
$ThrottleLimit, | |
<# | |
See Get-Help New-PSSessionOption. | |
#> | |
[Parameter()] | |
[Timespan] | |
$OpenTimeout, | |
<# | |
See Get-Help New-PSSessionOption. | |
#> | |
[Parameter()] | |
[Timespan] | |
$OperationTimeout, | |
<# | |
See Get-Help Invoke-Command. | |
#> | |
[Parameter()] | |
[switch] | |
$EnableNetworkAccess | |
) | |
begin { | |
$allComputers = [System.Collections.Generic.HashSet[string]]::new([StringComparer]::OrdinalIgnoreCase) | |
} | |
process { | |
foreach ($name in $ComputerName) { | |
$null = $allComputers.Add($name) | |
} | |
} | |
end { | |
$invokeSplat = @{ | |
ComputerName = $allComputers | |
HideComputerName = $true | |
} | |
if ($ThrottleLimit) { | |
$invokeSplat['ThrottleLimit'] = $ThrottleLimit | |
} | |
if ($EnableNetworkAccess) { | |
$invokeSplat['EnableNetworkAccess'] = $true | |
} | |
$optionSplat = @{} | |
if ($OpenTimeout) { | |
$optionSplat['OpenTimeout'] = $OpenTimeout | |
} | |
if ($OperationTimeout) { | |
$optionSplat['OperationTimeout'] = $OperationTimeout | |
} | |
if ($splat.Count) { | |
$invokeSplat['SessionOption'] = New-PSSessionOption @optionSplat | |
} | |
$namePattern = $PackageName.ForEach{ [Regex]::Escape($_) } -join '|' | |
Invoke-Command @invokeSplat -ScriptBlock { | |
$output = [Ordered]@{ | |
ComputerName = $env:COMPUTERNAME | |
} | |
foreach ($name in $using:PackageName) { | |
$output[$name] = 'Not detected' | |
} | |
Get-ItemProperty -Path @( | |
'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' | |
'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' | |
) | Where-Object DisplayName -match $using:namePattern | ForEach-Object { | |
$output[$matches[0]] = $_.DisplayVersion | |
} | |
[PSCustomObject]$output | |
} | Select-Object * -ExcludeProperty RunspaceId | |
} | |
} | |
Find-Software chrome, firefox -EnableNetworkAccess |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment