Skip to content

Instantly share code, notes, and snippets.

@rebrec
Created September 11, 2024 07:24
Show Gist options
  • Save rebrec/7e0759a712f564dd7431bee816695c13 to your computer and use it in GitHub Desktop.
Save rebrec/7e0759a712f564dd7431bee816695c13 to your computer and use it in GitHub Desktop.
Monitor MECM Deployment progress for specific device
# Extract Deployment information from MECM (SCCM) through WMI for a specific device.
# Useful to monitor specific devide deployment current progression state or to get some history informations
$ComputerName = "VM-XXX" # computer to find deployment information
$ExecutionTime = '20240327100900.000000+000' # date of the oldest log to extract
$SiteCode = "XYZ"
pushd "$($SiteCode):"
$steps = Get-WmiObject -ComputerName "srv-mecm-01" -Namespace "Root\SMS\site_$SiteCode" -Query "Select * from SMS_TaskSequenceExecutionStatus Where ResourceID='$(get-cmdevice -name $Computername -Fast | select -ExpandProperty ResourceId)' AND ExecutionTime > '$ExecutionTime'" `
| Select @{N = "Date"; E = { Get-Date -Date ([DateTime]::ParseExact(($_.ExecutionTime -split '\+')[0], "yyyyMMddHHmmss.ffffff", $null)) -Format "yyyy/MM/dd HH:mm:ss" } }, * `
| Select Step, LastStatusMsgName, ActionName, ActionOutput, Date -First (5000) `
| Sort-Object Date, Step
$steps | % {
$res = $_
switch ($res.LastStatusMsgName) {
{ $_ -like "*a group*" } { $hide = $true }
{ $_ -like "*disabled*" } { $type = "SKIP (Disabled)" }
{ $_ -like "*skipped*" } { $type = "SKIP" }
{ $_ -like "*successfully completed an action*" } { $type = "ACTION - SUCCESS" }
{ $_ -like "*failed executing an action*" } { $type = "ACTION - FAILURE" }
# Default { }
}
Write-Host "$($res.Date) Step $("$($res.Step)".PadLeft(3)) : $("$($type)".PadRight(20)) - $($res.ActionName)"
}
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment