Create a Custom Detection Script for Amazon WorkSpaces (PowerShell)

Microsoft Endpoint Manager Configuration Manager (MEMCM / SCCM) and Microsoft Intune use Detection Rules to determine the presence of Applications & Win32 Apps. The detection rules ensure that application installations only begin to run if the application is not already installed on the device. This article will serve as an informative guide and give you a clear understanding of how to create an updated custom detection script for each new version of Amazon WorkSpaces using PowerShell.

How to Create a Custom Detection Script for Amazon WorkSpaces

Amazon WorkSpaces (File Detection Method)

## Check for Amazon WorkSpaces (File Detection Method)
$WorkSpacesExe = (Get-ChildItem -Path "C:\Program Files\Amazon Web Services, Inc\Amazon WorkSpaces\workspaces.exe","C:\Program Files (x86)\Amazon Web Services, Inc\Amazon WorkSpaces\workspaces.exe" -ErrorAction SilentlyContinue)
$WorkSpacesExe.FullName
$WorkSpacesPath = $($WorkSpacesExe.FullName).Replace("C:\Program Files\","").Replace("C:\Program Files (x86)\","")
$FileVersion = (Get-Item -Path "$($WorkSpacesExe.FullName)" -ErrorAction SilentlyContinue).VersionInfo.FileVersion

## Create Text File with Amazon WorkSpaces File Detection Method
$FilePath = "C:\Windows\Temp\Amazon_WorkSpaces_Detection_Method.txt"
New-Item -Path "$FilePath" -Force
Set-Content -Path "$FilePath" -Value "If([String](Get-Item -Path `"`$Env:ProgramFiles\$WorkSpacesPath`",`"`${Env:ProgramFiles(x86)}\$WorkSpacesPath`" -ErrorAction SilentlyContinue).VersionInfo.FileVersion -ge `"$FileVersion`"){"
Add-Content -Path "$FilePath" -Value "Write-Host `"Installed`""
Add-Content -Path "$FilePath" -Value "}"
Invoke-Item $FilePath
  • Click Run Script (F5)
  • A text file will open with the Amazon WorkSpaces Detection Method script required to detect the current version of Amazon WorkSpaces that is installed on the device you are running the script from.

Example:

If([String](Get-Item -Path "$Env:ProgramFiles\Amazon Web Services, Inc\Amazon WorkSpaces\workspaces.exe","${Env:ProgramFiles(x86)}\Amazon Web Services, Inc\Amazon WorkSpaces\workspaces.exe" -ErrorAction SilentlyContinue).VersionInfo.FileVersion -ge "5.5.0.3276"){
Write-Host "Installed"
}

Amazon WorkSpaces (Registry Detection Method)

## Check for Amazon WorkSpaces (Registry Detection Method)
$WorkSpaces = Get-ChildItem -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall","HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | Get-ItemProperty | Where-Object {$_.DisplayName -like 'Amazon WorkSpaces*' } | Select-Object -Property DisplayName, DisplayVersion, PSChildName
$WorkSpaces.DisplayVersion
$WorkSpaces.PSChildName

## Create Text File with Amazon WorkSpaces Registry Detection Method
$FilePath = "C:\Windows\Temp\Amazon_WorkSpaces_Detection_Method.txt"
New-Item -Path "$FilePath" -Force
Set-Content -Path "$FilePath" -Value "If([Version](Get-ItemPropertyValue -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$($WorkSpaces.PSChildName)','HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\$($WorkSpaces.PSChildName)' -Name DisplayVersion -ea SilentlyContinue) -ge '$($WorkSpaces.DisplayVersion)') {"
Add-Content -Path "$FilePath" -Value "Write-Host `"Installed`""
Add-Content -Path "$FilePath" -Value "}"
Invoke-Item $FilePath
  • Click Run Script (F5)
  • A text file will open with the Amazon WorkSpaces Detection Method script required to detect the current version of Amazon WorkSpaces that is installed on the device you are running the script from.

Example:

If([Version](Get-ItemPropertyValue -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{8847527E-0A5A-4786-97CF-9E68670313CE}','HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{8847527E-0A5A-4786-97CF-9E68670313CE}' -Name DisplayVersion -ea SilentlyContinue) -ge '5.5.0.3276') {
Write-Host "Installed"
}

Always make sure to test everything in a development environment prior to implementing anything into production. The information in this article is provided “As Is” without warranty of any kind.