Powershell Application Detection

Topics: Archive - General
Jul 11, 2014 at 8:44 PM
Awesome tool, now that I have found this I need to read up on powershell! Being that I am not that well versed with Powershell scripting I am hoping someone tell me where i am going wrong.

I am trying to deploy an upgraded Citrix Receiver in our environment. I will be doing this via an SCCM Package. I am trying to query a specific key in the registry to determine the Receiver version installed HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Citrix\PluginPackages\XenAppSuite\PN_Agent\Version

If version is already value defined I would want this package not to even run for the user. If its not then proceed with killing processes and then install app.

Below is the script so far but it fails as I am trying to get-itemproperty.
# Determine if Citrix Receiver 3 is installed if so quit script
      $ReceiverVersion Get-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Citrix\PluginPackages\XenAppSuite\PN_Agent' -Name Version
            If ($ReceiverVersion -eq "13.1.300.8") {
            $Receiver3Installed = $true
            Break
    }
}

    # If Receiver is not up to date Show Welcome screen and kill Receiver processes
If ($Receiver3Installed -eq $false) {
    Show-InstallationWelcome -CloseApps "Receiver,pamain" -AllowDefer -DeferTimes 3
Jul 14, 2014 at 2:06 PM
I'm not well versed either, but I've been using something similar for detection methods that works for me.
# Determine if Citrix Receiver 3 is installed if so quit script
      $ReceiverVersion Get-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Citrix\PluginPackages\XenAppSuite\PN_Agent' -ErrorAction SilentlyContinue | Get-ItemProperty | Select "Version" -ExpandProperty "Version"
            If ($ReceiverVersion -ge "13.1.300.8") {
            $Receiver3Installed = $true
            Break
    }
}
I typically use -ge rather than -eq for certain apps just because at times others may have a higher version that they're using than the version approved or mandated by the company. This avoids uninstall/reinstall of their version because it fails version detection.
Coordinator
Jul 15, 2014 at 9:52 PM
Edited Jul 15, 2014 at 9:53 PM
Sample Citrix Receiver script:

https://psappdeploytoolkit.codeplex.com/discussions/470880

Here's the code you need - important bit is the [version] type cast:
[version]$CitrixVersion = Get-InstalledApplication "Citrix Receiver" | select "DisplayVersion" -expand "DisplayVersion" 

If ($CitrixVersion -lt [version]"13.1.300.8" -or $CitrixVersion -eq $null) {
     Execute-Process -FilePath "CitrixReceiver.exe" -Arguments "/noreboot /silent"    
} 
Jul 15, 2014 at 10:15 PM
Edited Jul 15, 2014 at 10:44 PM
Why not use the built in Get-InstalledApplication? Since you are looking for a specific version of Citrix, you can just snag that product code or target a specific Citrix plugin (looks like you want to check PNA) and do something like
$appVersion = Get-InstalledApplication "Citrix Receiver(PNA)" | % {$_.DisplayVersion} 
If ($appVersion -le '13.1.300.8') {
     Write-Host "it's less than or equal to"
}
Else {
     Write-Host "it's greater than"
}
You can use -eq or -ge and modify accordingly. That's usually what I use if I'm looking for something specific like that.

EDIT: Wow I took to long to write mine out... and his is more elegant anyway!
Jul 16, 2014 at 9:49 PM
thanks to all very much, appreciate your time and feedback! i have plenty of things to try now
Jul 17, 2014 at 2:34 PM
One thing that I have noticed with the detection method I posted, I occasionally receive reports from users that if they already have the latest version (or higher) the installation will show as "Failed" in SCCM... Is it missing an Exit Code? There is an Exit Code 0 at the end of the script, but I'm thinking I need one right after the Installed = True portion as well?
Jul 17, 2014 at 2:57 PM
Lipid_Venom wrote:
One thing that I have noticed with the detection method I posted, I occasionally receive reports from users that if they already have the latest version (or higher) the installation will show as "Failed" in SCCM... Is it missing an Exit Code? There is an Exit Code 0 at the end of the script, but I'm thinking I need one right after the Installed = True portion as well?
Lipid how are you deploying this via SCCM? Application or Package? Have you checked the SCCM logs on the workstation when it fails? Suppose you are deploying via an Application, you could check the AppEnforce.log to see why SCCM considers it a failed install.
Jul 17, 2014 at 3:43 PM
Quick question for you all, once you install the latest Receiver are you prompting users to restart their PC afterwards? Sounds silly but all the previous threads I have read indicate that its best to restart after the Receiver install. I would just like to know how others are accomplishing that in their environment. I could ask users to just launch a Published app after the upgrade but they will get prompted for their logon credentials to re-authenticate.

Could in theory I use the Show-InstallationRestartPrompt below?
#*===============================================
#* INSTALLATION 
$installPhase = "Installation"
#*===============================================

 # Install the Receiver 3.4 CU3 via VBscript
    Execute-Process -FilePath "cscript.exe" "`"$dirFiles\SCCM_Install.vbs`" /NoCancel" -WindowStyle Hidden
 # Restart Computer after Install of Citrix Receiver   
    Show-InstallationRestartPrompt -Countdownseconds 600 -CountdownNoHideseconds 60
Jul 17, 2014 at 4:16 PM
jguevarajr wrote:
Lipid_Venom wrote:
One thing that I have noticed with the detection method I posted, I occasionally receive reports from users that if they already have the latest version (or higher) the installation will show as "Failed" in SCCM... Is it missing an Exit Code? There is an Exit Code 0 at the end of the script, but I'm thinking I need one right after the Installed = True portion as well?
Lipid how are you deploying this via SCCM? Application or Package? Have you checked the SCCM logs on the workstation when it fails? Suppose you are deploying via an Application, you could check the AppEnforce.log to see why SCCM considers it a failed install.
+++ Application not discovered. [AppDT Id: ScopeId_8829C3AB-A8A5-486A-9846-BA94CAF6EEA6/DeploymentType_a555d5e8-218d-4958-b842-1c4aee0090f6, Revision: 6]   AppEnforce  
    App enforcement environment: Context: Machine Command line: ServiceUI.exe Deploy-Application.exe Install Allow user interaction: No UI mode: 1 User token: null Session Id: 1 Content path: C:\Windows\ccmcache\ct Working directory:   AppEnforce
 Prepared working directory: C:\Windows\ccmcache\ct AppEnforce  
    Prepared command line: "C:\Windows\ccmcache\ct\ServiceUI.exe" Deploy-Application.exe Install    AppEnforce
    Post install behavior is BasedOnExitCode    AppEnforce
    Waiting for process 6320 to finish.  Timeout = 120 minutes. AppEnforce
    Process 6320 terminated with exitcode: 1603 AppEnforce
    Looking for exit code 1603 in exit codes table...   AppEnforce
    Unmatched exit code (1603) is considered an execution failure.  AppEnforce
As I suspected, I should place an Exit-Code 0 = (Successful?) for when the Application is detected via the script. The actual issue is based off a faulty Detection Method within SCCM, the user should not have received this update to begin with.
Jul 17, 2014 at 4:31 PM
Lipid_Venom wrote:
jguevarajr wrote:
Lipid_Venom wrote:
One thing that I have noticed with the detection method I posted, I occasionally receive reports from users that if they already have the latest version (or higher) the installation will show as "Failed" in SCCM... Is it missing an Exit Code? There is an Exit Code 0 at the end of the script, but I'm thinking I need one right after the Installed = True portion as well?
Lipid how are you deploying this via SCCM? Application or Package? Have you checked the SCCM logs on the workstation when it fails? Suppose you are deploying via an Application, you could check the AppEnforce.log to see why SCCM considers it a failed install.
+++ Application not discovered. [AppDT Id: ScopeId_8829C3AB-A8A5-486A-9846-BA94CAF6EEA6/DeploymentType_a555d5e8-218d-4958-b842-1c4aee0090f6, Revision: 6]   AppEnforce  
    App enforcement environment: Context: Machine Command line: ServiceUI.exe Deploy-Application.exe Install Allow user interaction: No UI mode: 1 User token: null Session Id: 1 Content path: C:\Windows\ccmcache\ct Working directory:   AppEnforce
 Prepared working directory: C:\Windows\ccmcache\ct AppEnforce  
    Prepared command line: "C:\Windows\ccmcache\ct\ServiceUI.exe" Deploy-Application.exe Install    AppEnforce
    Post install behavior is BasedOnExitCode    AppEnforce
    Waiting for process 6320 to finish.  Timeout = 120 minutes. AppEnforce
    Process 6320 terminated with exitcode: 1603 AppEnforce
    Looking for exit code 1603 in exit codes table...   AppEnforce
    Unmatched exit code (1603) is considered an execution failure.  AppEnforce
As I suspected, I should place an Exit-Code 0 = (Successful?) for when the Application is detected via the script. The actual issue is based off a faulty Detection Method within SCCM, the user should not have received this update to begin with.
Lipid how are you handling the detection method of the application via SCCM? In my test application I configured the Detection to be MSI Product Code specific. Let SCCM 2012 Applications do the detection/work for you :) I decided to deploy with a Package instead as you have greater control of mandatory assignments on a recurring schedule.
Jul 17, 2014 at 5:20 PM
jguevarajr wrote:
Quick question for you all, once you install the latest Receiver are you prompting users to restart their PC afterwards? Sounds silly but all the previous threads I have read indicate that its best to restart after the Receiver install. I would just like to know how others are accomplishing that in their environment. I could ask users to just launch a Published app after the upgrade but they will get prompted for their logon credentials to re-authenticate.

Could in theory I use the Show-InstallationRestartPrompt below?
#*===============================================
#* INSTALLATION 
$installPhase = "Installation"
#*===============================================

 # Install the Receiver 3.4 CU3 via VBscript
    Execute-Process -FilePath "cscript.exe" "`"$dirFiles\SCCM_Install.vbs`" /NoCancel" -WindowStyle Hidden
 # Restart Computer after Install of Citrix Receiver   
    Show-InstallationRestartPrompt -Countdownseconds 600 -CountdownNoHideseconds 60
Yep, I'm restarting and also using the Show-InstallationRestartPrompt just like you are. I had tried to do it without a reboot and met with very mixed results. Our EMR is deployed via Citrix and it didn't work great until a reboot was performed.
Jul 17, 2014 at 5:55 PM
souporman wrote:
jguevarajr wrote:
Quick question for you all, once you install the latest Receiver are you prompting users to restart their PC afterwards? Sounds silly but all the previous threads I have read indicate that its best to restart after the Receiver install. I would just like to know how others are accomplishing that in their environment. I could ask users to just launch a Published app after the upgrade but they will get prompted for their logon credentials to re-authenticate.

Could in theory I use the Show-InstallationRestartPrompt below?
#*===============================================
#* INSTALLATION 
$installPhase = "Installation"
#*===============================================

 # Install the Receiver 3.4 CU3 via VBscript
    Execute-Process -FilePath "cscript.exe" "`"$dirFiles\SCCM_Install.vbs`" /NoCancel" -WindowStyle Hidden
 # Restart Computer after Install of Citrix Receiver   
    Show-InstallationRestartPrompt -Countdownseconds 600 -CountdownNoHideseconds 60
Yep, I'm restarting and also using the Show-InstallationRestartPrompt just like you are. I had tried to do it without a reboot and met with very mixed results. Our EMR is deployed via Citrix and it didn't work great until a reboot was performed.
Thanks for the input souporman can you post where you have the Show-InstallationRestartPrompt in your code? Perhaps Post-Installation is best place for it...
#*===============================================
#* INSTALLATION 
$installPhase = "Installation"
#*===============================================

 # Install the Receiver 3.4 CU3 via VBscript
    Execute-Process -FilePath "cscript.exe" "`"$dirFiles\SCCM_Install.vbs`" /NoCancel" -WindowStyle Hidden
 
#*===============================================
#* POST-INSTALLATION
$installPhase = "Post-Installation"
#*===============================================

# Restart Computer after Install of Citrix Receiver   
    Show-InstallationRestartPrompt -Countdownseconds 600 -CountdownNoHideseconds 60
Jul 17, 2014 at 6:21 PM
Edited Jul 17, 2014 at 6:22 PM
That's exactly right! Also, I strongly recommend looking at the example Citrix script PowerSheller linked to. Closing those running applications in the Pre-Installation steps is super important for Citrix upgrades!
Oct 29, 2014 at 4:15 PM
Here is a detection method for version 14.1.200.13

$osarch = (gwmi win32_operatingsystem).osarchitecture
if ($osarch -eq "64-bit") {
$ReceiverVersion = (Get-ItemProperty -Path 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\CitrixOnlinePluginPackWeb' -ErrorAction SilentlyContinue).DisplayVersion
if ($ReceiverVersion -eq '14.1.200.13') {
    Write-Host 'Installed'
    }
} else {
$ReceiverVersion = (Get-ItemProperty -Path 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\CitrixOnlinePluginPackWeb' -ErrorAction SilentlyContinue).DisplayVersion
if ($ReceiverVersion -eq '14.1.200.13') {
    Write-Host 'Installed'
    }
}