Trevor Sullivan's Tech Room

Minding the gap between administration and development

PowerShell / ConfigMgr: Sendsched.vbs Replacement

Posted by Trevor Sullivan on 2011/07/25


Recently, someone posted a PowerShell script, which is intended as a replacement for the SendSched.vbs included in the Microsoft System Center Configuration Manager 2007 Toolkit v2.

I took the liberty of cleaning the code up a little bit, and simplifying it to be more PowerShell friendly. Enjoy.

#            
# Script Name: SendSched_PowerShell_Version.ps1
# Purpose: Serves as a replacement for the sendsched.vbs script included in the Microsoft System Center
#            Configuration Manager 2007 toolkit -- asynchronously invokes SCCM client tasks
#            
# Created By Kaido Jarvemets Http://Depsharee.blogspot.com            
# Configuration Manager MVP            
# 25.07.2011

# Updated by: Trevor Sullivan
#      Email: pcgeek86@gmail.com
#         Blog: http://trevorsullivan.net
#        Date: 2011-07-25
#
# Changelog:
#        * Replaced Get-ScheduleID function with a hashtable
#        * Removed custom ping function in favor of using Test-Connection
#        * Replaced default computer name with a period, which represents localhost
            
function Invoke-SCCMSchedule            
{            
    [CmdletBinding()]            
    Param(            
        [String]$ComputerName = ".",
        [Parameter(Mandatory = $true)]            
        [string]$ScheduleID
        
    )            
               
    $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            
        AMTProvisionCycle    = "{00000000-0000-0000-0000-000000000120}"; # AMT Provision Cycle            
    }
    
    if(Test-Connection -Computer $ComputerName) {
        Try {
            $SmsClient = [wmiclass]"\\$ComputerName\root\ccm`:SMS_Client"
            $SmsClient.TriggerSchedule($ScheduleIds.$ScheduleID)
          }            
        Catch {
            Write-Host "Trigger Schedule Method failed" -ForegroundColor RED            
        }            
    }            
    else {
        Write-Host "Computer may be offline or please check Windows Firewall settings" -ForegroundColor Red
    }
             
}# End of Function Invoke-SCCMSchedule
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: