I'm trying to write to a .js file based on the contents of a text file (C:\installedApps.txt) using PowerShell.
The installedApps.txt
file contains the name and version of installed applications on a computer - I want to search installedApps.txt
for an application name and version and have the result assigned to the $findAppName
and $findAppVer
variables respectively.
I then want to write to a .js file IF the Select-String cmdlet is successful in matching the $appName
and $appVer
arguments passed into the Check-Install function. See code below:
function Check-Install ([string]$appName, [string]$appVer) {
$findAppName = Get-Content C:\installedApps.txt | Select-String $appName
$findAppver = Get-Content C:\installedApps.txt | Select-String $appVer
if ($findAppName -and $findAppVer -eq $true) {
Set-Content -path $jsFile -Value "var row = getElementById('row-1');
row.classList.add('hidden');"
} else {
write-host Match Not Found
}
}
Check-Install -appName "Cisco AnyConnect Secure Mobility Client" -appVer "4.6.01103"
The $findAppName
and $findAppVer
variables aren't returning anything, but not sure where I'm going wrong - the Select-String cmdlet should accept variables(?).
Note: No errors thrown up in the shell
UPDATE:
Here's an example of how the installedApps.txt log is formatted:
DisplayName : 7-Zip 18.05 (x64)
Publisher : Igor Pavlov
InstallDate :
DisplayVersion : 18.05
UninstallString : C:\Program Files\7-Zip\Uninstall.exe
DisplayName : Adobe Flash Player 31 NPAPI
Publisher : Adobe Systems Incorporated
InstallDate :
DisplayVersion : 31.0.0.122
UninstallString :
C:\WINDOWS\SysWOW64\Macromed\Flash\FlashUtil32_31_0_0_122_Plugin.exe -
maintain plugin
DisplayName : Adobe Flash Player 31 PPAPI
Publisher : Adobe Systems Incorporated
InstallDate :
DisplayVersion : 31.0.0.122
UninstallString :
C:\WINDOWS\SysWOW64\Macromed\Flash\FlashUtil32_31_0_0_122_pepper.exe -
maintain pepperplugin
DisplayName : Cisco AnyConnect Secure Mobility Client
Publisher : Cisco Systems, Inc.
InstallDate : 20180906
DisplayVersion : 4.6.01103
UninstallString : MsiExec.exe /X{58524593-122C-43F0-96E2-A6BCC42E3412}
I want to trigger an application install/uninstall (without using the WMI object, as I've read it takes a while and can trigger an installation repair on query) and write to a local web page based on the $findApp results via a .js file to show whether the application is already installed or not.
I'm trying to create a software update script with a front-end written in HTML, CSS and JavaScript for the UI. The script will run on logon across multiple computers in a domain. I'll need to use Ajax to find a way to update the local web page dynamically without a page refresh, but one step at a time.