if (Test-Path C:\Apps\Test.html)
{
Write-Host "Installed"
}
else
{
}
The above code snippet illustrates that the SCCM Client is looking for a state of “Installed” , the if statement contains the logic to indicate what is tested before this state is set. I expanded upon this code with the following:
Set-ExecutionPolicy -ExecutionPolicy Bypass
##Global Variable Declaration
[version]$InstallerVersion = '8.0.1210.13'
#Application Name as it appears in HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{appGUID}\DisplayName
#Append a * as a wildcard ex. '7-Zip*'
$AppName = 'Java*'
##32-Bit Detection
$32BitApp = Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | where {$_.displayname -like $AppName}
Foreach ($item in $32BitApp)
{
[version]$InstalledVersion = $item.DisplayVersion
if ($InstalledVersion -ge $InstallerVersion)
{
Write-Host "Installed"
}
else
{
}
}
##64-Bit Detection
$64BitApp = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | where {$_.displayname -like $AppName}
Foreach ($item in $64BitApp)
{
[version]$InstalledVersion = $item.DisplayVersion
if ($InstalledVersion -ge $InstallerVersion)
{
Write-Host "Installed"
}
else
{
}
}
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (2)
Commented:
Which of the Powershell line that I can edit safely to suit my environment ?
Author
Commented:[version]$InstallerVersion
$AppName = 'Java*'
The value of $AppName variable is a wildcard string that corresponds with the DisplayName registry value, where as $InstalledVersion corresponds to DisplayVersion.
You can modify any part of the script to accommodate any type of detection method and use and/or statements to create a more restrictive set of criteria. The goal of my example is to make the SCCM client agent believe that Java is installed if its version is greater than or equal to the value of $InstallerVersion in the Variable Declaration section