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 Atlassian Companion using PowerShell.
How to Create a Custom Detection Script for Atlassian Companion
Atlassian Companion EXE (Registry Detection Method)
- Install the version of Atlassian Companion you want to deploy on a test box or VM
- Check out the following posts for further details
- Open Windows PowerShell ISE by Right-Clicking on Windows PowerShell ISE and selecting Run as Administrator
- Copy the following code into the Windows PowerShell ISE
## Check for Atlassian Companion EXE (Registry Detection Method) $AtlassianCompanion = Get-ChildItem -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall" | Get-ItemProperty | Where-Object {$_.DisplayName -match 'Atlassian Companion' } | Select-Object -Property DisplayName, DisplayVersion, PSChildName $AtlassianCompanion.DisplayVersion $AtlassianCompanion.PSChildName ## Create Text File with Atlassian Companion EXE Registry Detection Method $FilePath = "C:\Windows\Temp\Atlassian_Companion_Detection_Method.txt" New-Item -Path "$FilePath" -Force Set-Content -Path "$FilePath" -Value "Function Get-LoggedOnUserSID {" Add-Content -Path "$FilePath" -Value "## ref https://www.reddit.com/r/PowerShell/comments/7coamf/query_no_user_exists_for/" Add-Content -Path "$FilePath" -Value "## ref https://smsagent.blog/2022/03/03/user-context-detection-rules-for-intune-win32-apps/" Add-Content -Path "$FilePath" -Value "`$header=@('SESSIONNAME', 'USERNAME', 'ID', 'STATE', 'TYPE', 'DEVICE')" Add-Content -Path "$FilePath" -Value "`$Sessions = query session" Add-Content -Path "$FilePath" -Value "[array]`$ActiveSessions = `$Sessions | Select -Skip 1 | Where {`$_ -match ""Active""}" Add-Content -Path "$FilePath" -Value "If (`$ActiveSessions.Count -ge 1)" Add-Content -Path "$FilePath" -Value "{" Add-Content -Path "$FilePath" -Value "`$LoggedOnUsers = @()" Add-Content -Path "$FilePath" -Value "`$indexes = `$header | ForEach-Object {(`$Sessions[0]).IndexOf("" `$_"")}" Add-Content -Path "$FilePath" -Value "for(`$row=0; `$row -lt `$ActiveSessions.Count; `$row++)" Add-Content -Path "$FilePath" -Value "{" Add-Content -Path "$FilePath" -Value "`$obj=New-Object psobject" Add-Content -Path "$FilePath" -Value "for(`$i=0; `$i -lt `$header.Count; `$i++)" Add-Content -Path "$FilePath" -Value "{" Add-Content -Path "$FilePath" -Value "`$begin=`$indexes[`$i]" Add-Content -Path "$FilePath" -Value "`$end=if(`$i -lt `$header.Count-1) {`$indexes[`$i+1]} else {`$ActiveSessions[`$row].length}" Add-Content -Path "$FilePath" -Value "`$obj | Add-Member NoteProperty `$header[`$i] (`$ActiveSessions[`$row].substring(`$begin, `$end-`$begin)).trim()" Add-Content -Path "$FilePath" -Value "}" Add-Content -Path "$FilePath" -Value "`$LoggedOnUsers += `$obj" Add-Content -Path "$FilePath" -Value "}" Add-Content -Path "$FilePath" -Value "`$LoggedOnUser = `$LoggedOnUsers[0]" Add-Content -Path "$FilePath" -Value "`$LoggedOnUserSID = Get-ItemProperty ""HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\SessionData\`$(`$LoggedOnUser.ID)"" -Name LoggedOnUserSID -ErrorAction SilentlyContinue |" Add-Content -Path "$FilePath" -Value "Select -ExpandProperty LoggedOnUserSID" Add-Content -Path "$FilePath" -Value "Return `$LoggedOnUserSID" Add-Content -Path "$FilePath" -Value "}" Add-Content -Path "$FilePath" -Value "}" Add-Content -Path "$FilePath" -Value "`$LoggedOnUserSID = Get-LoggedOnUserSID" Add-Content -Path "$FilePath" -Value "If (`$null -ne `$LoggedOnUserSID)" Add-Content -Path "$FilePath" -Value "{" Add-Content -Path "$FilePath" -Value "If (`$null -eq (Get-PSDrive -Name HKU -ErrorAction SilentlyContinue))" Add-Content -Path "$FilePath" -Value "{" Add-Content -Path "$FilePath" -Value "`$null = New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS" Add-Content -Path "$FilePath" -Value "}" Add-Content -Path "$FilePath" -Value "`$i = Get-Item ""HKU:\`$LoggedOnUserSID\Software\Microsoft\Windows\CurrentVersion\Uninstall\$($AtlassianCompanion.PSChildName)"" -ErrorAction SilentlyContinue" Add-Content -Path "$FilePath" -Value "if (`$null -eq `$i)" Add-Content -Path "$FilePath" -Value "{" Add-Content -Path "$FilePath" -Value "## Key Does NOT Exist" Add-Content -Path "$FilePath" -Value """Key Does NOT Exist""" Add-Content -Path "$FilePath" -Value "Exit 1" Add-Content -Path "$FilePath" -Value "}" Add-Content -Path "$FilePath" -Value "else" Add-Content -Path "$FilePath" -Value "{" Add-Content -Path "$FilePath" -Value "`$r = Get-ItemProperty ""HKU:\`$LoggedOnUserSID\Software\Microsoft\Windows\CurrentVersion\Uninstall\$($AtlassianCompanion.PSChildName)"" -Name 'DisplayVersion' -ErrorAction SilentlyContinue |" Add-Content -Path "$FilePath" -Value "Select -ExpandProperty 'DisplayVersion'" Add-Content -Path "$FilePath" -Value "If (`$r -ge '$($AtlassianCompanion.DisplayVersion)')" Add-Content -Path "$FilePath" -Value "{" Add-Content -Path "$FilePath" -Value "## Installed" Add-Content -Path "$FilePath" -Value """Installed""" Add-Content -Path "$FilePath" -Value "Exit 0" Add-Content -Path "$FilePath" -Value "}" Add-Content -Path "$FilePath" -Value "else" Add-Content -Path "$FilePath" -Value "{" Add-Content -Path "$FilePath" -Value "## Correct App Version NOT Installed" Add-Content -Path "$FilePath" -Value """Correct App Version NOT Installed""" Add-Content -Path "$FilePath" -Value "Exit 1" Add-Content -Path "$FilePath" -Value "}" Add-Content -Path "$FilePath" -Value "}" Add-Content -Path "$FilePath" -Value "}" Add-Content -Path "$FilePath" -Value "Else" Add-Content -Path "$FilePath" -Value "{" Add-Content -Path "$FilePath" -Value "## No Logged on User Detected" Add-Content -Path "$FilePath" -Value """No Logged on User Detected""" Add-Content -Path "$FilePath" -Value "Exit 1" Add-Content -Path "$FilePath" -Value "}" Invoke-Item $FilePath
- Click Run Script (F5)
- A text file will open with the Atlassian Companion Detection Method script required to detect the current version of Atlassian Companion that is installed on the device you are running the script from.
Example:
Function Get-LoggedOnUserSID { ## ref https://www.reddit.com/r/PowerShell/comments/7coamf/query_no_user_exists_for/ ## ref https://smsagent.blog/2022/03/03/user-context-detection-rules-for-intune-win32-apps/ $header=@('SESSIONNAME', 'USERNAME', 'ID', 'STATE', 'TYPE', 'DEVICE') $Sessions = query session [array]$ActiveSessions = $Sessions | Select -Skip 1 | Where {$_ -match "Active"} If ($ActiveSessions.Count -ge 1) { $LoggedOnUsers = @() $indexes = $header | ForEach-Object {($Sessions[0]).IndexOf(" $_")} for($row=0; $row -lt $ActiveSessions.Count; $row++) { $obj=New-Object psobject for($i=0; $i -lt $header.Count; $i++) { $begin=$indexes[$i] $end=if($i -lt $header.Count-1) {$indexes[$i+1]} else {$ActiveSessions[$row].length} $obj | Add-Member NoteProperty $header[$i] ($ActiveSessions[$row].substring($begin, $end-$begin)).trim() } $LoggedOnUsers += $obj } $LoggedOnUser = $LoggedOnUsers[0] $LoggedOnUserSID = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\SessionData\$($LoggedOnUser.ID)" -Name LoggedOnUserSID -ErrorAction SilentlyContinue | Select -ExpandProperty LoggedOnUserSID Return $LoggedOnUserSID } } $LoggedOnUserSID = Get-LoggedOnUserSID If ($null -ne $LoggedOnUserSID) { If ($null -eq (Get-PSDrive -Name HKU -ErrorAction SilentlyContinue)) { $null = New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS } $i = Get-Item "HKU:\$LoggedOnUserSID\Software\Microsoft\Windows\CurrentVersion\Uninstall\atlassian-desktop-companion" -ErrorAction SilentlyContinue if ($null -eq $i) { ## Key Does NOT Exist "Key Does NOT Exist" Exit 1 } else { $r = Get-ItemProperty "HKU:\$LoggedOnUserSID\Software\Microsoft\Windows\CurrentVersion\Uninstall\atlassian-desktop-companion" -Name 'DisplayVersion' -ErrorAction SilentlyContinue | Select -ExpandProperty 'DisplayVersion' If ($r -ge '1.4.1') { ## Installed "Installed" Exit 0 } else { ## Correct App Version NOT Installed "Correct App Version NOT Installed" Exit 1 } } } Else { ## No Logged on User Detected "No Logged on User Detected" Exit 1 }
- Copy the Atlassian Companion Detection Method script content into the Custom Detection Rules (Script)
- Microsoft Endpoint Manager Configuration Manager (MEMCM / SCCM)
- Microsoft Intune
Atlassian Companion MSI (File Detection Method)
- Install the version of Atlassian Companion you want to deploy on a test box or VM
- Check out the following posts for further details
- Open Windows PowerShell ISE by Right-Clicking on Windows PowerShell ISE and selecting Run as Administrator
- Copy the following code into the Windows PowerShell ISE
## Check for Atlassian Companion MSI (File Detection Method) $AtlassianCompanionExe = (Get-ChildItem -Path "C:\Program Files\Atlassian Companion\Atlassian Companion.exe","C:\Program Files (x86)\Atlassian Companion\Atlassian Companion.exe" -ErrorAction SilentlyContinue) $AtlassianCompanionExe.FullName $AtlassianCompanionPath = $($AtlassianCompanionExe.FullName).Replace("C:\Program Files\","").Replace("C:\Program Files (x86)\","") $FileVersion = (Get-Item -Path "$($AtlassianCompanionExe.FullName)" -ErrorAction SilentlyContinue).VersionInfo.FileVersion ## Create Text File with Atlassian Companion MSI File Detection Method $FilePath = "C:\Windows\Temp\Atlassian_Companion_Detection_Method.txt" New-Item -Path "$FilePath" -Force Set-Content -Path "$FilePath" -Value "If([String](Get-Item -Path `"`$Env:ProgramFiles\$AtlassianCompanionPath`",`"`${Env:ProgramFiles(x86)}\$AtlassianCompanionPath`" -ErrorAction SilentlyContinue).VersionInfo.FileVersion -ge `"$FileVersion`"){" Add-Content -Path "$FilePath" -Value "Write-Host `"Installed`"" Add-Content -Path "$FilePath" -Value "Exit 0" Add-Content -Path "$FilePath" -Value "}" Add-Content -Path "$FilePath" -Value "else {" Add-Content -Path "$FilePath" -Value "Exit 1" Add-Content -Path "$FilePath" -Value "}" Invoke-Item $FilePath
- Click Run Script (F5)
- A text file will open with the Atlassian Companion Detection Method script required to detect the current version of Atlassian Companion that is installed on the device you are running the script from.
Example:
If([String](Get-Item -Path "$Env:ProgramFiles\Atlassian Companion\Atlassian Companion.exe","${Env:ProgramFiles(x86)}\Atlassian Companion\Atlassian Companion.exe" -ErrorAction SilentlyContinue).VersionInfo.FileVersion -ge "1.4.1.0"){ Write-Host "Installed" Exit 0 } else { Exit 1 }
- Copy the Atlassian Companion Detection Method script content into the Custom Detection Rules (Script)
- Microsoft Endpoint Manager Configuration Manager (MEMCM / SCCM)
- Microsoft Intune
Atlassian Companion MSI (Registry Detection Method)
- Install the version of Atlassian Companion you want to deploy on a test box or VM
- Check out the following posts for further details
- Open Windows PowerShell ISE by Right-Clicking on Windows PowerShell ISE and selecting Run as Administrator
- Copy the following code into the Windows PowerShell ISE
## Check for Atlassian Companion MSI (Registry Detection Method) $AtlassianCompanion = Get-ChildItem -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall","HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | Get-ItemProperty | Where-Object {$_.DisplayName -like 'Atlassian Companion (Machine)*' } | Select-Object -Property DisplayName, DisplayVersion, PSChildName $AtlassianCompanion.DisplayVersion $AtlassianCompanion.PSChildName ## Create Text File with Atlassian Companion MSI Registry Detection Method $FilePath = "C:\Windows\Temp\Atlassian_Companion_Detection_Method.txt" New-Item -Path "$FilePath" -Force Set-Content -Path "$FilePath" -Value "If([Version](Get-ItemPropertyValue -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$($AtlassianCompanion.PSChildName)','HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\$($AtlassianCompanion.PSChildName)' -Name DisplayVersion -ea SilentlyContinue) -ge '$($AtlassianCompanion.DisplayVersion)') {" Add-Content -Path "$FilePath" -Value "Write-Host `"Installed`"" Add-Content -Path "$FilePath" -Value "Exit 0" Add-Content -Path "$FilePath" -Value "}" Add-Content -Path "$FilePath" -Value "else {" Add-Content -Path "$FilePath" -Value "Exit 1" Add-Content -Path "$FilePath" -Value "}" Invoke-Item $FilePath
- Click Run Script (F5)
- A text file will open with the Atlassian Companion Detection Method script required to detect the current version of Atlassian Companion that is installed on the device you are running the script from.
Example:
If([Version](Get-ItemPropertyValue -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{5158057E-2AEE-454A-8847-EED63CA0E4DF}.msq','HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{5158057E-2AEE-454A-8847-EED63CA0E4DF}.msq' -Name DisplayVersion -ea SilentlyContinue) -ge '1.4.1') { Write-Host "Installed" Exit 0 } else { Exit 1 }
- Copy the Atlassian Companion Detection Method script content into the Custom Detection Rules (Script)
- Microsoft Endpoint Manager Configuration Manager (MEMCM / SCCM)
- Microsoft Intune
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.