Search code examples
powershelldeploymentpropertiesschedulesccm

SCCM Powershell - Retrieving a "lazy" property


Let's say I run:

Get-CMDeployment -CollectionName "gar25*" | select CollectionName, ApplicationName, PackageID, DeploymentTime, EnforcementDeadline | out-gridview

enter image description here

This gives me all the info I need on multiple deployments associated to a user, but the value "EnforcementDeadline" is blank, which i'm guessing is a lazy property. How would I retrieve it? I have found this article:

https://trevorsullivan.net/2010/09/28/powershell-configmgr-wmi-provider-feat-lazy-properties/#comment-3628074206

but i'm really struggling to adapt the code.

Thanks a lot for your time.


Solution

  • EnforcementDeadline is a property for application deployments. You're trying to read it from a package deployment where it doesn't exist because they can have multiple assigned schedules which can be both one time or recurring (ex. daily). If you use Get-CMApplicationDeployment and Get-CMPackageDeployment you will get the right type of objects so you can access the values.

    I've included a sample that will detect if the deployment is for a package and retrieve the StartTime-values for it's schedules (I assume they are non-reccuring).

    $DeadlineColumn = @{
        Name="EnforcementDeadline"
        Expression={
            if($_.FeatureType -eq 2 -or $_.FeatureType -eq 7) {
                #Package or task sequence
                #Get assignment-starttime (ignoring daily/hourly etc.)
                (Get-CMPackageDeployment -DeploymentId $_.DeploymentID).AssignedSchedule | Select-Object -ExpandProperty StartTime
            } else {
                #Application
                $_.EnforcementDeadline
            }
        }
    }
    
    Get-CMDeployment -CollectionName "abc" | select CollectionName, ApplicationName, PackageID, DeploymentTime, $DeadlineColumn | out-gridview