I'm working on a PowerShell script to check if a specific application, like Google Chrome, is installed by looking at the registry uninstall keys. The function I'm using, `CheckApp`, currently returns a boolean value to indicate whether the app is found. However, I want to return additional details such as `DisplayVersion`, `InstallDate`, and `PSPath` of the app when it is installed. How can I modify my function to pass these details to the second part of my script?
4 Answers
Instead of returning a boolean value, you should return the `$item` object that contains all the needed properties. This way, in your second part of the script, you can directly access `DisplayVersion`, `InstallDate`, and `PSPath`. Update your condition to check if the result is not `$false` instead of checking for true.
To return more information than just true or false, you can modify the `CheckApp` function to return a PSCustomObject with the app details. Instead of returning `$true`, return the `$item` when the matching display name is found. Then, in the second part of your script, check if the result is not `$null` to see if the app is installed and access the properties directly from the returned object.
One way to achieve this is by changing your `CheckApp` function to return the `$item` object. This object contains all the custom properties like `DisplayVersion` and others which you can use later. Here's a quick snippet:
```powershell
function CheckApp {
# ... your existing paths code ...
foreach ($item in $items) {
if ($item.DisplayName -like "*$AppName*") {
return $item
}
}
return $null
}
```
If you'd like to keep things simple, you could just have a separate function that handles the notification part using the properties from the registry. Your `CheckApp` function can find the app, and then you pass the found item to this new function that sends the data to Teams.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically