1
0
mirror of https://github.com/jaapbrasser/SharedScripts.git synced 2025-12-24 21:51:38 +02:00

Added functionality to filter similar programnames

This commit is contained in:
Jaap Brasser
2016-08-26 15:20:39 +02:00
parent 33d0adac18
commit 7a1bbca4f1

View File

@@ -7,12 +7,12 @@ Generates a list of installed programs on a computer
This function generates a list by querying the registry and returning the installed programs of a local or remote computer.
.NOTES
Name: Get-RemoteProgram
Author: Jaap Brasser
Version: 1.2.1
Name : Get-RemoteProgram
Author : Jaap Brasser
Version : 1.3
DateCreated: 2013-08-23
DateUpdated: 2015-02-28
Blog: http://www.jaapbrasser.com
DateUpdated: 2016-08-26
Blog : http://www.jaapbrasser.com
.LINK
http://www.jaapbrasser.com
@@ -23,6 +23,12 @@ The computer to which connectivity will be checked
.PARAMETER Property
Additional values to be loaded from the registry. Can contain a string or an array of string that will be attempted to retrieve from the registry for each program entry
.PARAMETER ExcludeSimilar
This will filter out similar programnames, the default value is to filter on the first 3 words in a program name. If a program only consists of less words it is excluded and it will not be filtered. For example if you Visual Studio 2015 installed it will list all the components individually, using -ExcludeSimilar will only display the first entry.
.PARAMETER SimilarWord
This parameter only works when ExcludeSimilar is specified, it changes the default of first 3 words to any desired value.
.EXAMPLE
Get-RemoteProgram
@@ -46,16 +52,28 @@ Will gather the list of programs from Server01 and attempts to retrieve the disp
Description
Will retrieve the installed programs on server01/02 that are passed on to the function through the pipeline and also retrieves the uninstall string for each program
.EXAMPLE
'server01','server02' | Get-RemoteProgram -Property Uninstallstring -ExcludeSimilar -SimilarWord 4
Description
Will retrieve the installed programs on server01/02 that are passed on to the function through the pipeline and also retrieves the uninstall string for each program. Will only display a single entry of a program of which the first four words are identical.
#>
[CmdletBinding(SupportsShouldProcess=$true)]
param(
[Parameter(ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
[Parameter(ValueFromPipeline =$true,
ValueFromPipelineByPropertyName=$true,
Position=0
)]
[string[]]
$ComputerName = $env:COMPUTERNAME,
[Parameter(Position=0)]
[string[]]$Property
[string[]]
$Property,
[switch]
$ExcludeSimilar,
[int]
$SimilarWord
)
begin {
@@ -71,7 +89,8 @@ Will retrieve the installed programs on server01/02 that are passed on to the fu
process {
foreach ($Computer in $ComputerName) {
$RegBase = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine,$Computer)
foreach ($CurrentReg in $RegistryLocation) {
$RegistryLocation | ForEach-Object {
$CurrentReg = $_
if ($RegBase) {
$CurrentRegKey = $RegBase.OpenSubKey($CurrentReg)
if ($CurrentRegKey) {
@@ -90,6 +109,26 @@ Will retrieve the installed programs on server01/02 that are passed on to the fu
}
}
}
} | ForEach-Object -Begin {
if ($SimilarWord) {
$Regex = [regex]"(^(.+?\s){$SimilarWord}).*$|(.*)"
} else {
$Regex = [regex]"(^(.+?\s){3}).*$|(.*)"
}
[System.Collections.ArrayList]$Array = @()
} -Process {
if ($ExcludeSimilar) {
$null = $Array.Add($_)
} else {
$_
}
} -End {
if ($ExcludeSimilar) {
$Array | Select-Object -Property *,@{name='GroupedName';expression={($_.ProgramName -split $Regex)[1]}} |
Group-Object -Property 'GroupedName' | ForEach-Object {
$_.Group[0] | Select-Object -Property * -ExcludeProperty GroupedName
}
}
}
}
}