I use PowerShell to check, if specific apps are installed on the users PC:
$Application_MicrosoftEdge = get-package "Microsoft Edge" | % { $_.metadata['installlocation'] }
$Application_Microsoft365 = get-package *"Microsoft 365"* | % { $_.metadata['installlocation'] }
Write-Host "Microsoft Edge Path : $Application_MicrosoftEdge"
Write-Host "Microsoft 365 Path : $Application_Microsoft365"
This works quiet well, but if an application is not installed on the users PC, then an error message is shown (here "Microsoft 365" is not installed on the PC):
get-package : Für "*Microsoft 365*" wurde kein Paket gefunden.
In D:\Scripts\GetInstalledApp.ps1:12 Zeichen:32
+ $Application_Microsoft365 = get-package *"Microsoft 365"* | % { $ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.Power...lets.GetPackage:GetPackage) [Get-Package], Exception
+ FullyQualifiedErrorId : NoMatchFound,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackage
I tried the following way, but here an error message is shown:
Try {
$Application_MicrosoftEdge = get-package "Microsoft Edge" | % { $_.metadata['installlocation'] }
$Application_Microsoft365 = get-package *"Microsoft 365"* | % { $_.metadata['installlocation'] }
}
Catch {
# Place action on error here
}
I also tried to wrap it in $( ... ) | out-null to suppress the error, but this is also not working.
`
Any idea?