0

In my script, I have match Installed computer program with my text file, If the installed program is match with my taxt file then showing same program name in Installed-App column, if it is not match displaying "Not Installed". I Want Hightlight "Not Installed" in RED color which is define in $apps = [PSCustomObject]@{RequirApp=$requirapp; $systemapp="Not Installed"}. Can you help me out anyone. Hear is my code

$appname  = Get-Content -path $env:USERPROFILE\Documents\Installed-Applications.txt

$INSTALLED = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate
$INSTALLED += Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate
$INSTALLED += Get-ItemProperty HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate
#$INSTALLED | ?{$_.DisplayName -ne $null} | Select-Object -Property DisplayName | out-file $env:USERPROFILE\Documents\Installed-Applications.txt
$sysapps = $INSTALLED | ?{$_.DisplayName -ne $null}

for($i=0; $i -lt $sysapps.Count; $i++)
{
    $installapp += $sysapps[$i].DisplayName
}

foreach($a in $appname)
{
        $requirapp = $a
          
        if($installapp -contains $requirapp.Trim())
        {
           
           $apps = [PSCustomObject]@{RequirApp=$requirapp; $systemapp=$requirapp} 
           
        }
        else
        {
            
            $apps = [PSCustomObject]@{RequirApp=$requirapp; $systemapp="Not Installed"}
            
        }  
        $apps
       
  }

Script output

I want output as image

zett42
  • 25,437
  • 3
  • 35
  • 72
  • 2
    Can you use PowerShell 7? This makes the task easier using ANSI escape sequences. – zett42 Feb 23 '23 at 09:57
  • Does this answer your question? https://stackoverflow.com/questions/73558709/powershell-different-color-in-strings-with-echo-in-array/73558896 – Santiago Squarzon Feb 23 '23 at 12:16
  • No, My need is different of that question. I want to be set foreground or background color on specific word like **"Not Installed" in [PSCustomObject] key value** – Chirag Darji Feb 23 '23 at 13:36
  • That's exactly what the answer is showing. For Foreground you need to use a different escape sequence but that's out of the question and for your own research – Santiago Squarzon Feb 23 '23 at 13:43
  • If you want the ANSI escape sequence for RGB color for background or foreground, take a look at this [answer](https://stackoverflow.com/a/71184802/4190564). – Darin Feb 24 '23 at 01:03

0 Answers0