1 min read

Powershell - Get PackageID Executionhistory _State

This is a short script to fast and easy get the executionhistory _state from an PackageID deployment, to find out how an deployment has gone.

I use it with Configuration Item / baseline's to create Compliance collections or in CM's "Run Script" function to fast "query" a device of its _state.


param(
    [Parameter(Mandatory = $true, HelpMessage = "Enter the PackageID that you want to check state")]
    [ValidateNotNullOrEmpty()]
    [string]$PackageID
)

$ExecutionHistoryKey = "HKLM:\SOFTWARE\Microsoft\SMS\Mobile Client\Software Distribution\Execution History\System\$PackageID"
$ExecutionHistorySubKey = Get-ChildItem $ExecutionHistoryKey | Select -ExpandProperty Name
$PackageExecutionHistoryKey = $ExecutionhistorySubKey -Replace "HKEY_LOCAL_MACHINE","HKLM:"
$_State = (Get-ItemProperty $PackageExecutionHistoryKey)._State
Write-Output $_State