Trigger ConfigMgr client actions

A few weeks ago, I came across the following article on refreshing the System Center Configuration Management client

Whenever I see a script, I always wonder, could it be done with a oneliner ?
sms_client-actions-01

As long as the script doesn’t care about the order of the ConfigMgr actions to be performed, yes, it’s achievable this way:

(New-Object -COM 'CPApplet.CPAppletMgr').GetClientActions() | 
Where { 
    $_.Name -match "(\sPolicy$)|(Collection\sCycle$)|(Updates)"
} | ForEach-Object {
    try {
        $_.PerformAction()
        Write-Verbose -Message "Successfully executed $($_.Name)" -Verbose
    } catch {
        Write-Warning -Message "Failed to execute $($_.Name)"
    }
}

I’ve even added some filtering on action names and error handling.

sms_client-actions-02
There’s always more than one way to skin a cat with PowerShell 😉

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