I have multiple functions that check if software is installed then writes to a CSV file. Here's two. I will have 10 functions like this. The functions get called in a foreach loop. Everything is functional but I've heard if you have to copy and paste a lot that means you need to rethink your code. I just cant figure out the best way to consolidate these
function Find-Silverlight { # Detects if silverlight is installed
[CmdletBinding()]
param ()
$silverlight = invoke-command -computername $row.hostname -scriptblock {Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\ |
Get-ItemProperty | Select-Object DisplayName, DisplayVersion | where-object DisplayName -like *silverlight*}
if ($silverlight) {
$row.Silverlight = "$($silverlight.DisplayVersion)"
write-verbose "$($silverlight.Displayname) $($silverlight.DisplayVersion)"
}
else {
write-verbose "Microsoft Silverlight not detected"
$row.Silverlight = "Not Detected"
}
}
function Find-Chrome { # Detects if Google Chrome is installed
[CmdletBinding()]
param ()
$chrome = invoke-command -computername $row.hostname -scriptblock {Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\ |
Get-ItemProperty | Select-Object DisplayName, DisplayVersion | where-object DisplayName -like *chrome*}
if ($chrome) {
$row.Chrome = "$($chrome.DisplayVersion)"
write-verbose "$($chrome.Displayname) $($chrome.DisplayVersion)"
}
else {
write-verbose "Google Chrome not detected."
$row.Chrome = "Not Detected"
}
}