A friend of mine asked me on Twitter today if I had a script that would list all applications in ConfigMgr 2012 where the Logon Requirement under the User Experience tab was set to Only when a user is logged on. A while back I made a PowerShell script that would enumerate all Applications and get the Command line for each Deployment Type. I figured that since I already had most of the code already, this shouldn’t be that hard.

Below is a picture of what he was asking about:

99_1

I found that there are two ways to go about this. The easiest way would be to enumerate all instances in the SMS_ApplicationLatest WMI class. For every instance in this class, there’s a property called LogonRequirement. Here’s the behavior of this property.

LogonRequirement is set to 1 when the following setting is configured:

  • Only when a user is logged on

LogonRequirement is set to 0 when one of the following settings is configured:

  • Whether or not a user is logged on
  • Only when no user is logged on

Instead of enumerating all of the instances, I reused parts of my old script where I deserialize the SDMPackageXML and goes through each Deployment Type. On the Deployment Type, there’s a Installer property, and below that there’s a property called RequiresLogon. In my lab environment it seemed that this property had the same behavior as for the LogonRequirement from the WMI class. The only difference was that when the Only when a user is logged on setting was configured, the RequiresLogon property would be set to True. If one of the other settings was configured, the RequiresLogon property would not be set to anything.

The script

I ended up using the following script that creates a custom object for each application where the Logon Requirement is set to Only when a user is logged on.

[CmdletBinding()]
param(
[parameter(Mandatory=$true)]
$SiteServer,
[parameter(Mandatory=$true)]
$SiteCode
)

try {
    [System.Reflection.Assembly]::LoadFrom((Join-Path (Get-Item $env:SMS_ADMIN_UI_PATH).Parent.FullName "Microsoft.ConfigurationManagement.ApplicationManagement.dll")) | Out-Null
    [System.Reflection.Assembly]::LoadFrom((Join-Path (Get-Item $env:SMS_ADMIN_UI_PATH).Parent.FullName "Microsoft.ConfigurationManagement.ApplicationManagement.Extender.dll")) | Out-Null
    [System.Reflection.Assembly]::LoadFrom((Join-Path (Get-Item $env:SMS_ADMIN_UI_PATH).Parent.FullName "Microsoft.ConfigurationManagement.ApplicationManagement.MsiInstaller.dll")) | Out-Null
}
catch {
    Write-Error $_.Exception.Message
}

$Applications = Get-WmiObject -Namespace "root\SMS\site_$($SiteCode)" -Class "SMS_Application" -ComputerName $SiteServer -Filter 'IsLatest = "True"'
$Applications | ForEach-Object {
    $LocalizedDisplayName = $_.LocalizedDisplayName
    $CurrentApplication = [wmi]$_.__PATH
    $ApplicationXML = [Microsoft.ConfigurationManagement.ApplicationManagement.Serialization.SccmSerializer]::DeserializeFromString($CurrentApplication.SDMPackageXML,$True)
    foreach ($DeploymentType in $ApplicationXML.DeploymentTypes) {
        $Object = New-Object -TypeName PSObject
        $RequiresLogon = {
            $GetRequiresLogon = $DeploymentType.Installer.RequiresLogOn
            $GetRequiresLogon
            if ($GetRequiresLogon -eq "True") {
                return "True"
            }
            else {
                return "False"
            }
        }
        if ($RequiresLogon.Invoke() -eq "True") {
            $Object | Add-Member -MemberType NoteProperty -Name ApplicationName -Value $LocalizedDisplayName
            $Object | Add-Member -MemberType NoteProperty -Name RequiresLogon -Value "True"
            Write-Output $Object
        }
        else {
            Write-Output "`nNo applications was found that requires a user to be logged on for the installation to start`n"
        }
    }
}

To run the script, save it as e.g. Get-CMApplicationLogonRequirement.ps1 to C:\Scripts.

1. Open an elevated PowerShell console on your Primary Site server (or CAS).
2. Browse to C:\Scripts and run the following command:

.\Get-CMApplicationLogonRequirement.ps1 -SiteServer CAS01 -SiteCode CAS

Note! Don’t forget to amend the command above with your own site server and site code.

The picture below shows the output from the script when a match is found.

99_2

I hope this helps someone else as well, have a great weekend!

Nickolaj Andersen
Principal Consultant and Enterprise Mobility MVP. Nickolaj has been in the IT industry for the past 10 years specializing in Enterprise Mobility and Security, Windows deployments and Automation. In 2015 Nickolaj was awarded as PowerShell Hero by the community for his script and tools contributions. Author of ConfigMgr Prerequisites Tool, ConfigMgr OSD FrontEnd, ConfigMgr WebService and a frequent speaker at user groups.

(55)

comments
  • Michael Briggs
    Posted at 22:31 November 12, 2014
    Michael Briggs
    Reply
    Author

    This is great! thanks

    I have a request on a similar tack. How do I find Packages that are advertised to users as Required? I found out a few days ago, someone had “required” acrobat to several users. As the users went around logging onto machines, acrobat licenses started to disappear!

  • Julien
    Posted at 16:20 March 10, 2016
    Julien
    Reply
    Author

    Hello

    First – thank you for your help to SCCM community users like us !

    This script (show user experience settings) works well and i would like to transform it for getting the product code for each application in the Detection Method tab (instead of showing user experience settings), maybe in a csv file.
    Is it possible ?

    Why : because i need to compare all theses product code in this detection method tab with product codes really installed by our packages (some times some product code are differents because of a MST file applied), i can get easily installed product code with using MSSQL requests in our old SCCM2007 infrastructure, but i don’t know how to extract product code for each application in lazy properties with SCM2012. The goal is to avoid failed deployments when CM client check if applications are installed (compliant). I don’t want to check each Application one by one 🙂
    Thx

  • Leave a Reply