Invoke-SCCMTask 3.5.0

Topics: Archive - General
Mar 3, 2015 at 6:05 PM
First I love this tool!!! It has become our standard in cm12 app deployments, at least where complex apps are needed.

Been looking over the appdeploytoolkitmain.ps1 file for the new release 3.5.0 (I do this before I upgrade my systems) and I found that there were a couple of items from the invoke-sccmtask section that may no longer be needed (can't run them with sendschedule.exe) and a couple that were missing.

Here is my updated section of the script:

Function Invoke-SCCMTask {
<#
.SYNOPSIS
Triggers SCCM to invoke the requested schedule task id.
.DESCRIPTION
Triggers SCCM to invoke the requested schedule task id.
.PARAMETER ScheduleId
Schedule Id.
.PARAMETER ContinueOnError
Continue if an error is encountered.
.EXAMPLE
Invoke-SCCMTask 'SoftwareUpdatesScan'
.EXAMPLE
Invoke-SCCMTask
.NOTES
.LINK
http://psappdeploytoolkit.codeplex.com

>

[CmdletBinding()]
Param (
    [Parameter(Mandatory=$true)]
    <#[ValidateSet('HardwareInventory','SoftwareInventory','HeartbeatDiscovery','SoftwareInventoryFileCollection','RequestMachinePolicy','EvaluateMachinePolicy','LocationServicesCleanup','SoftwareMeteringReport','SourceUpdate','PolicyAgentCleanup','RequestMachinePolicy2','CertificateMaintenance','PeerDistributionPointStatus','PeerDistributionPointProvisioning','ComplianceIntervalEnforcement','SoftwareUpdatesAgentAssignmentEvaluation','UploadStateMessage','StateMessageManager','SoftwareUpdatesScan','AMTProvisionCycle')]#>
    [ValidateSet('HardwareInventory','SoftwareInventory','HeartbeatDiscovery','SoftwareInventoryFileCollection','RequestMachinePolicy','EvaluateMachinePolicy','LocationServicesCleanup','SoftwareMeteringReport','SourceUpdate','PolicyAgentCleanup','RequestMachinePolicy2','CertificateMaintenance','SoftwareUpdatesAgentAssignmentEvaluation','UploadStateMessage','StateMessageManager','SoftwareUpdatesScan','UpdateStorePolicy','StateSystemBulkSend','AMTProvisionCycle','ApplicationManagerPolicyAction','PowerManagementStartSummeraizer')]
    [string]$ScheduleID,
    [Parameter(Mandatory=$false)]
    [ValidateNotNullorEmpty()]
    [boolean]$ContinueOnError = $true
)

Begin {
    ## Get the name of this function and write header
    [string]${CmdletName} = $PSCmdlet.MyInvocation.MyCommand.Name
    Write-FunctionHeaderOrFooter -CmdletName ${CmdletName} -CmdletBoundParameters $PSBoundParameters -Header

    [hashtable]$ScheduleIds = @{
        HardwareInventory = '{00000000-0000-0000-0000-000000000001}'; # Hardware Inventory Collection Task
        SoftwareInventory = '{00000000-0000-0000-0000-000000000002}'; # Software Inventory Collection Task
        HeartbeatDiscovery = '{00000000-0000-0000-0000-000000000003}'; # Heartbeat Discovery Cycle
        SoftwareInventoryFileCollection = '{00000000-0000-0000-0000-000000000010}'; # Software Inventory File Collection Task
        RequestMachinePolicy = '{00000000-0000-0000-0000-000000000021}'; # Request Machine Policy Assignments
        EvaluateMachinePolicy = '{00000000-0000-0000-0000-000000000022}'; # Evaluate Machine Policy Assignments
        RefreshDefaultMp = '{00000000-0000-0000-0000-000000000023}'; # Refresh Default MP Task
        RefreshLocationServices = '{00000000-0000-0000-0000-000000000024}'; # Refresh Location Services Task
        LocationServicesCleanup = '{00000000-0000-0000-0000-000000000025}'; # Location Services Cleanup Task
        SoftwareMeteringReport = '{00000000-0000-0000-0000-000000000031}'; # Software Metering Report Cycle
        SourceUpdate = '{00000000-0000-0000-0000-000000000032}'; # Source Update Manage Update Cycle
        PolicyAgentCleanup = '{00000000-0000-0000-0000-000000000040}'; # Policy Agent Cleanup Cycle
        RequestMachinePolicy2 = '{00000000-0000-0000-0000-000000000042}'; # Request Machine Policy Assignments
        CertificateMaintenance = '{00000000-0000-0000-0000-000000000051}'; # Certificate Maintenance Cycle
        #PeerDistributionPointStatus = '{00000000-0000-0000-0000-000000000061}'; # Peer Distribution Point Status Task
        #PeerDistributionPointProvisioning = '{00000000-0000-0000-0000-000000000062}'; # Peer Distribution Point Provisioning Status Task
        #ComplianceIntervalEnforcement = '{00000000-0000-0000-0000-000000000071}'; # Compliance Interval Enforcement
        SoftwareUpdatesAgentAssignmentEvaluation = '{00000000-0000-0000-0000-000000000108}'; # Software Updates Agent Assignment Evaluation Cycle
        UploadStateMessage = '{00000000-0000-0000-0000-000000000111}'; # Send Unsent State Messages
        StateMessageManager = '{00000000-0000-0000-0000-000000000112}'; # State Message Manager Task
        SoftwareUpdatesScan = '{00000000-0000-0000-0000-000000000113}'; # Force Update Scan
        UpdateStorePolicy = '{00000000-0000-0000-0000-000000000114}'; # Update Store Policy
        StateSystemBulkSend = '{00000000-0000-0000-0000-000000000116}'; # State System Policy bulk send low
        AMTProvisionCycle = '{00000000-0000-0000-0000-000000000120}'; # AMT Provision Cycle
        ApplicationManagerPolicyAction = '{00000000-0000-0000-0000-000000000121}'; # Application Manager Policy Action
        PowerManagementStartSummeraizer = '{00000000-0000-0000-0000-000000000131}'; # Power Management Start Summarizer
    }
}
Process {
    Write-Log -Message "Invoke SCCM Schedule Task ID [$ScheduleId]..." -Source ${CmdletName}

    ## Trigger SCCM task
    Try {
        [System.Management.ManagementClass]$SmsClient = [WMIClass]'ROOT\CCM:SMS_Client'
        $SmsClient.TriggerSchedule($ScheduleIds.$ScheduleID) | Out-Null
    }
    Catch {
        Write-Log -Message "Failed to trigger SCCM Schedule Task ID [$($ScheduleIds.$ScheduleId)]. `n$(Resolve-Error)" -Severity 3 -Source ${CmdletName}
        If (-not $ContinueOnError) {
            Throw "Failed to trigger SCCM Schedule Task ID [$($ScheduleIds.$ScheduleId)]: $($_.Exception.Message)"
        }
    }
}
End {
    Write-FunctionHeaderOrFooter -CmdletName ${CmdletName} -Footer
}
}

endregion

Coordinator
Mar 3, 2015 at 9:46 PM
Thanks for sharing this, we can include in the next release but can you explain why you have 2 different ValidateSet sections for $scheduleID?
Mar 5, 2015 at 1:07 PM
One is commented out. I do that until I am sure all is well.

Thank You,



Roger Truss
[email removed]
h (920) 456-8302
c (920) 203-0625

Mar 7, 2015 at 10:33 PM
Would it be better to test first if SCCM is already install?
set-variable -name var_class -visibility public -Scope Script -Value ""
$var_class = Get-WmiObject -List | Where-Object {$_.__NAMESPACE -eq 'root\ccm' -and $_.__CLASS -eq 'sms_client'}
Will it be maintain with the future version of SCCM?

If its not sure then you should check the SCCM version first. Then in the future if the SCCM infrastructure is upgrade then there will no error or problem. Not sure how establishing the current sccm version.
Developer
Mar 12, 2015 at 11:18 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.