Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invoke-SCCMClientAction #341

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions Client/Invoke-SCCMClientAction.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<#
.SYNOPSIS
Invoke the specified SCCM client actions on the computer
.DESCRIPTION
This script will execute the supplied SCCM client actions on the target computer
.PARAMETER Computername
Computer name on which to run the actions
.EXAMPLE
$Policies = 'ApplicationDeploymentEvaluationCycle', 'DiscoveryDataCollectionCycle', 'FileCollectionCycle', 'HardwareInventoryCycle', 'MachinePolicyRetrievalCycle', 'MachinePolicyEvaluationCycle', 'SoftwareInventoryCycle', 'SoftwareMeteringUsageReportCycle', 'SoftwareUpdatesAssignmentsEvaluationCycle', 'SoftwareUpdateScanCycle', 'StateMessageRefresh', 'UserPolicyRetrievalCycle', 'UserPolicyEvaluationCycle', 'WindowsInstallersSourceListUpdateCycle'
Invoke-SCCMClientAction -computername $ENV:COMPUTERNAME -ClientAction $Policies
.NOTES
Script name: Invoke-SCCMClientAction
Author: Devin Stokes
DateCreated: 2021-12-15
#>
Function Invoke-SCCMClientAction {
[CmdletBinding()]

# Parameters used in this function
param
(
[Parameter(Position = 0, Mandatory = $True, HelpMessage = "Provide server names", ValueFromPipeline = $true)]
[string[]]$Computername,

[ValidateSet('ApplicationDeploymentEvaluationCycle',
'DiscoveryDataCollectionCycle',
'FileCollectionCycle',
'HardwareInventoryCycle',
'MachinePolicyRetrievalCycle',
'MachinePolicyEvaluationCycle',
'SoftwareInventoryCycle',
'SoftwareMeteringUsageReportCycle',
'SoftwareUpdatesAssignmentsEvaluationCycle',
'SoftwareUpdateScanCycle',
'StateMessageRefresh',
'UserPolicyRetrievalCycle',
'UserPolicyEvaluationCycle',
'WindowsInstallersSourceListUpdateCycle')]
[string[]]$ClientAction

)
$ActionResults = @()
Try {
$ActionResults = Invoke-Command -ComputerName $Computername { param([array]$ClientAction)
"Executing $($ClientAction.Length) actions on $env:COMPUTERNAME..." | Out-Host

Foreach ($Item in $ClientAction) {
$Object = @{} | select "Action name", Status
Try {
$ScheduleIDMappings = @{
'ApplicationDeploymentEvaluationCycle' = "{00000000-0000-0000-0000-000000000121}";
'DiscoveryDataCollectionCycle' = "{00000000-0000-0000-0000-000000000003'}";
'FileCollectionCycle' = "{00000000-0000-0000-0000-000000000010}";
'HardwareInventoryCycle' = "{00000000-0000-0000-0000-000000000001'}";
'MachinePolicyRetrievalCycle' = "{00000000-0000-0000-0000-000000000021}";
'MachinePolicyEvaluationCycle' = "{00000000-0000-0000-0000-000000000022}";
'SoftwareInventoryCycle' = "{00000000-0000-0000-0000-000000000002}";
'SoftwareMeteringUsageReportCycle' = "{00000000-0000-0000-0000-000000000031}";
'SoftwareUpdatesAssignmentsEvaluationCycle' = "{00000000-0000-0000-0000-000000000108}";
'SoftwareUpdateScanCycle' = "{00000000-0000-0000-0000-000000000113}";
'StateMessageRefresh' = "{00000000-0000-0000-0000-000000000111}";
'UserPolicyRetrievalCycle' = "{00000000-0000-0000-0000-000000000026}";
'UserPolicyEvaluationCycle' = "{00000000-0000-0000-0000-000000000027}";
'WindowsInstallersSourceListUpdateCycle' = "{00000000-0000-0000-0000-000000000032}"
}
$ScheduleID = $ScheduleIDMappings[$item]
Write-Verbose "Processing $Item - $ScheduleID"
[void]([wmiclass] "root\ccm:SMS_Client").TriggerSchedule($ScheduleID);
$Status = "Success"
Write-Verbose "Operation status - $status"
}
Catch {
$Status = "Failed"
Write-Verbose "Operation status - $status"
}
$Object."Action name" = $item
$Object.Status = $Status
$Object
}

} -ArgumentList (, $ClientAction) -ErrorAction Stop | Select-Object @{n = 'ServerName'; e = { $_.pscomputername } }, "Action name", Status
}
Catch {
Write-Error $_.Exception.Message
}
Return $ActionResults
}