Calculate Percent on Compliance SCCM Powershell by Device collection

%3CLINGO-SUB%20id%3D%22lingo-sub-1797819%22%20slang%3D%22en-US%22%3ECalculate%20Percent%20on%20Compliance%20SCCM%20Powershell%20by%20Device%20collection%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1797819%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22p1%22%3E%3CSPAN%20class%3D%22s1%22%3EI%20have%20a%20function%20that%20pulls%20compliance%20status%20of%20a%20software%20update%20deployment%20(assignment%20ID).%20I%20want%20to%20configure%20this%20to%20calculate%20percent%20of%20the%20status%20types%20(Success%2C%20Error%2C%20In%20Progress%2C%20Unknown)%20and%20I%20would%20also%20like%20to%20pull%20compliance%20status%20based%20on%20device%20collection%20name%20instead%20of%20the%20deployment%20ID%20as%20it%20is%20shown%20below.%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p2%22%3E%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3EWhat%20I%20want%20to%20accomplish%20is%20automatically%20take%20a%20list%20of%20device%20collection%20names%20and%20run%20a%20software%20update%20deployment%20which%20organizes%20each%20collection%20by%20compliance%20percent%20(for%20each%20status)%2C%20and%20then%20receive%20it%20by%20email%20every%20morning.%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p2%22%3E%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3EI%20have%20several%20locations%20based%20on%20device%20collection%2C%20and%20I%20want%20to%20be%20able%20to%20differentiate%20which%20locations%20and%20devices%20are%20the%20problematic%20ones.%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p2%22%3E%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3EThis%20method%20makes%20tracking%20and%20reporting%20much%20easier%20and%20SCCM%20console%20will%20not%20have%20to%20be%20launched%20each%20individual%20time%20to%20get%20reporting.%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p2%22%3E%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22p2%22%3E%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3Efunction%20Get-SCCMSoftwareUpdateStatus%20%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%5BCmdletBinding()%5D%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20param(%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%5BParameter()%5D%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%5Bswitch%5D%26nbsp%3B%20%24DeploymentIDFromGUI%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%5BParameter(Mandatory%20%3D%20%24false)%5D%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%5BAlias('ID'%2C%20'AssignmentID')%5D%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%5Bstring%5D%26nbsp%3B%20%26nbsp%3B%24DeploymentID%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%5BParameter(Mandatory%20%3D%20%24false)%5D%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%5BValidateSet('Success'%2C%20'InProgress'%2C%20'Error'%2C%20'Unknown')%5D%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%5BAlias('Filter')%5D%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%5Bstring%5D%26nbsp%3B%20%24Status%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20)%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20BEGIN%20%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%24Site_Code%26nbsp%3B%20%26nbsp%3B%3D%20'ABC'%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%24Site_Server%20%3D%20'SYSTEMCENTERSERVERNAME'%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%24HasErrors%26nbsp%3B%20%26nbsp%3B%3D%20%24False%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20(%24Status%20-eq%20'Success')%20%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%24StatusType%20%3D%201%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20(%24Status%20-eq%20'InProgress')%20%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%24StatusType%20%3D%202%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20(%24Status%20-eq%20'Unknown')%20%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%24StatusType%20%3D%204%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20(%24Status%20-eq%20'Error')%20%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%24StatusType%20%3D%205%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20PROCESS%20%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20try%20%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20(%24DeploymentID%20-and%20%24DeploymentIDFromGUI)%20%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20Write-Error%20%22Select%20the%20DeploymentIDFromGUI%20or%20DeploymentID%20Parameter.%20Not%20Both%22%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%24HasErrors%26nbsp%3B%20%26nbsp%3B%3D%20%24True%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20throw%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20(%24DeploymentIDFromGUI)%20%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%24ShellLocation%20%3D%20Get-Location%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20Import-Module%20(Join-Path%20%24(Split-Path%20%24env%3ASMS_ADMIN_UI_PATH)%20ConfigurationManager.psd1)%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%23Checking%20to%20see%20if%20module%20has%20been%20imported.%20If%20not%20abort.%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20(Get-Module%20ConfigurationManager)%20%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20Set-Location%20%22%24(%24Site_Code)%3A%5C%22%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%24DeploymentID%20%3D%20Get-CMSoftwareUpdateDeployment%20%7C%20select%20AssignmentID%2C%20AssignmentName%20%7C%20Out-GridView%20-OutputMode%20Single%20-Title%20%22Select%20a%20Deployment%20and%20Click%20OK%22%20%7C%20Select%20-ExpandProperty%20AssignmentID%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20Set-Location%20%24ShellLocation%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%20else%20%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20Write-Error%20%22The%20SCCM%20Module%20wasn't%20imported%20successfully.%20Aborting.%22%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%24HasErrors%26nbsp%3B%20%26nbsp%3B%3D%20%24True%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20throw%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20(%24DeploymentID)%20%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%24DeploymentNameWithID%20%3D%20Get-WMIObject%20-ComputerName%20%24Site_Server%20-Namespace%20root%5Csms%5Csite_%24Site_Code%20-class%20SMS_SUMDeploymentAssetDetails%20-Filter%20%22AssignmentID%20%3D%20%24DeploymentID%22%20%7C%20select%20AssignmentID%2C%20AssignmentName%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%24DeploymentName%20%3D%20%24DeploymentNameWithID.AssignmentName%20%7C%20select%20-Unique%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%20else%20%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20Write-Error%20%22A%20Deployment%20ID%20was%20not%20specified.%20Aborting.%22%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%24HasErrors%26nbsp%3B%20%26nbsp%3B%3D%20%24True%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20throw%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20(%24Status)%20%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%24Output%20%3D%20Get-WMIObject%20-ComputerName%20%24Site_Server%20-Namespace%20root%5Csms%5Csite_%24Site_Code%20-class%20SMS_SUMDeploymentAssetDetails%20-Filter%20%22AssignmentID%20%3D%20%24DeploymentID%20and%20StatusType%20%3D%20%24StatusType%22%20%7C%20%60%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20select%20DeviceName%2C%20CollectionName%2C%20%40%7BName%20%3D%20'StatusTime'%3B%20Expression%20%3D%20%7B%24_.ConvertToDateTime(%24_.StatusTime)%20%7D%7D%2C%20%40%7BName%20%3D%20'Status'%20%3B%20Expression%20%3D%20%7Bif%20(%24_.StatusType%20-eq%201)%20%7B'Success'%7D%20elseif%20(%24_.StatusType%20-eq%202)%20%7B'InProgress'%7D%20elseif%20(%24_.StatusType%20-eq%205)%20%7B'Error'%7D%20elseif%20(%24_.StatusType%20-eq%204)%20%7B'Unknown'%7D%26nbsp%3B%20%7D%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%20else%20%7B%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%24Output%20%3D%20Get-WMIObject%20-ComputerName%20%24Site_Server%20-Namespace%20root%5Csms%5Csite_%24Site_Code%20-class%20SMS_SUMDeploymentAssetDetails%20-Filter%20%22AssignmentID%20%3D%20%24DeploymentID%22%20%7C%20%60%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20select%20DeviceName%2C%20CollectionName%2C%20%40%7BName%20%3D%20'StatusTime'%3B%20Expression%20%3D%20%7B%24_.ConvertToDateTime(%24_.StatusTime)%20%7D%7D%2C%20%40%7BName%20%3D%20'Status'%20%3B%20Expression%20%3D%20%7Bif%20(%24_.StatusType%20-eq%201)%20%7B'Success'%7D%20elseif%20(%24_.StatusType%20-eq%202)%20%7B'InProgress'%7D%20elseif%20(%24_.StatusType%20-eq%205)%20%7B'Error'%7D%20elseif%20(%24_.StatusType%20-eq%204)%20%7B'Unknown'%7D%26nbsp%3B%20%7D%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20(-not%20%24Output)%20%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20Write-Error%20%22A%20Deployment%20with%20ID%3A%20%24(%24DeploymentID)%20is%20not%20valid.%20Aborting%22%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%24HasErrors%26nbsp%3B%20%26nbsp%3B%3D%20%24True%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20throw%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%20catch%20%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%20finally%20%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20((%24HasErrors%20-eq%20%24false)%20-and%20(%24Output))%20%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20Write-Output%20%22%22%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20Write-Output%20%22Deployment%20Name%3A%20%24DeploymentName%22%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20Write-Output%20%22Deployment%20ID%3A%26nbsp%3B%20%26nbsp%3B%24DeploymentID%22%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20Write-Output%20%22%22%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20Write-Output%20%24Output%20%7C%20Sort-Object%20Status%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%20%26nbsp%3B%20END%20%7B%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22p3%22%3E%3CSPAN%20class%3D%22s2%22%3E%7D%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1797819%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESystem%20Center%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESystem%20Center%20Configuration%20Manager%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1805579%22%20slang%3D%22en-US%22%3ERe%3A%20Calculate%20Percent%20on%20Compliance%20SCCM%20Powershell%20by%20Device%20collection%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1805579%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F366550%22%20target%3D%22_blank%22%3E%40NAN2019%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3EI%20had%20a%20small%20question%20just%20to%20confirm%20that%20I%20understand%20your%20question%2C%20so%20what%20you%20need%20is%20to%20get%20the%20result%20for%20all%20the%20deployment%20packages%20which%20listed%20in%20the%20following%20line%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24DeploymentID%20%3D%20Get-CMSoftwareUpdateDeployment%20%7C%20select%20AssignmentID%2C%20AssignmentName%20%7C%20Out-GridView%20-OutputMode%20Single%20-Title%20%22Select%20a%20Deployment%20and%20Click%20OK%22%20%7C%20Select%20-ExpandProperty%20AssignmentID%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3Band%20get%20the%20percentage%20of%20how%20many%20deployment%20was%20success%2C%20failure%20...etc%3C%2FP%3E%3CP%3Eso%20the%20output%20will%20look%20like%3C%2FP%3E%3CP%3ESuccess%3A%2040%25%3C%2FP%3E%3CP%3EError%3A%202%25%3C%2FP%3E%3CP%3EUnknown%3A%2050%25%3C%2FP%3E%3CP%3Eand%20so%20on%2C%20Yes%3F!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1809583%22%20slang%3D%22en-US%22%3ERe%3A%20Calculate%20Percent%20on%20Compliance%20SCCM%20Powershell%20by%20Device%20collection%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1809583%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F790105%22%20target%3D%22_blank%22%3E%40farismalaeb%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E1)%20Yes.%20I%20would%20like%20to%20show%20a%20clear%20percentage%20of%20each%20status%20(for%20example%3A%20Success%2012%25%20%2C%2040%25%20failed)%2C%20for%20the%20Software%20update%20deployment.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E2)%20The%202nd%20request%20was%20to%20take%20the%20specific%20software%20update%20deployment%20and%20run%20it%20against%20device%20collection%20names.%20Maybe%20the%20device%20collection%20could%20either%20be%20in%20a%20for-each%20statement%20or%20if%20its%20possible%20to%20take%20the%20device%20collection%20name%20itself%20and%20do%20it.%20So%20in%20a%20sense%20I%20would%20have%3A%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EChicago%20-%2075%25%20success%2C%2025%25%20failed%2C%200%25%20In%20progress%2C%200%25%20failed%3C%2FP%3E%3CP%3ECleveland%20-%26nbsp%3B25%25%20success%2C%2025%25%20failed%2C%2050%25%20In%20progress%2C%200%25%20failed%3C%2FP%3E%3CP%3EHouston%20-%26nbsp%3B75%25%20success%2C%2025%25%20failed%2C%200%25%20In%20progress%2C%200%25%20failed%3C%2FP%3E%3CP%3EMiami%20-%26nbsp%3B0%25%20success%2C%2025%25%20failed%2C%2025%25%20In%20progress%2C%2050%25%20failed%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnd%20I%20would%20like%20it%20to%20be%20in%20a%20csv%20as%20well%20as%20in%20the%20txt%20body%20of%20an%20email%20sent%20every%20morning.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1814909%22%20slang%3D%22en-US%22%3ERe%3A%20Calculate%20Percent%20on%20Compliance%20SCCM%20Powershell%20by%20Device%20collection%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1814909%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F366550%22%20target%3D%22_blank%22%3E%40NAN2019%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20wrote%20a%20quick%20update%20for%20script%2C%20review%20the%20change%20and%20test%20it%2C%20I%20don't%20have%20a%20big%20SCCM%20env%2C%20but%20this%20seems%20to%20be%20as%20you%20want.%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EFunction%20Get-AllPackages%7B%0A%24AllPack%20%3D%20Get-CMSoftwareUpdateDeployment%20%7C%20select%20AssignmentID%2C%20AssignmentName%0Areturn%20%24AllPack%0A%7D%20%0A%0A%24Packages%3D%20Get-AllPackages%0A%0Aforeach%20(%24SinglePack%20in%20%24Packages)%20%7B%0AWrite-Host%20%22--------------%22%0A%20%20%20%20Write-Host%20%24SinglePack.AssignmentName%0A%20%20%20%20%24packinfo%3DGet-SCCMSoftwareUpdateStatus%20-DeploymentID%20%24SinglePack.AssignmentID%20%0A%20%20%20%20%20%20%20%20%24Status%3D%24packinfo.status%20%7C%20Get-Unique%0A%20%20%20%20%20%20%20%20foreach%20(%24sinlgestatus%20in%20%24Status)%7B%0A%20%20%20%20%20%20%20%20Write-Host%20%22The%20Status%20of%20%24(%24sinlgestatus)%20for%20%24(%24SinglePack.AssignmentName)%22%20%0A%20%20%20%20%20%20%20%20%20%20%20%20(((%24packinfo%20%7C%20where%20%7B%24_.status%20-like%20%24sinlgestatus%7D)).status.count%20%2F%20(%24packinfo.Count%20-4)).tostring(%22P%22)%0A%20%20%20%20%20%20%20%20%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%7D%20%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThere%20is%20no%20change%20on%20the%20main%20function%2C%20I%20added%20extra%20function%20and%20some%20foreach%20loop%20to%20get%20the%20status.%26nbsp%3B%3C%2FP%3E%3CP%3EHope%20it%20helps%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E---------------%3C%2FP%3E%3CP%3EIf%20the%20above%20reply%20answers%20your%20question%2C%20please%20don't%20forget%20to%20click%20on%20Best%20Response.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1815846%22%20slang%3D%22en-US%22%3ERe%3A%20Calculate%20Percent%20on%20Compliance%20SCCM%20Powershell%20by%20Device%20collection%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1815846%22%20slang%3D%22en-US%22%3E%3CP%3EHere%20is%20what%20I%20get.%20See%20error%20output%20below.%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3ESo%20seems%20like%20this%20grabs%20all%20assignment%20ID%E2%80%99s%2C%20which%20would%20be%20every%20software%20update%20deployment.%20May%20be%20too%20much%20data%20even%20if%20I%20get%20is%20working.%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3EHow%20about%20a%20specific%20Assignment%20ID%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EAt%20line%3A1%20char%3A173%0A%2B%20...%20%24AllPack%20%7D%20%24Packages%3D%20Get-AllPackages%20foreach%20(%24SinglePack%20in%20%24Packag%20...%0A%2B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20~~%0AUnexpected%20token%20'in'%20in%20expression%20or%20statement.%0AAt%20line%3A1%20char%3A172%0A%2B%20...%20rn%20%24AllPack%20%7D%20%24Packages%3D%20Get-AllPackages%20foreach%20(%24SinglePack%20in%20%24Pac%20...%0A%2B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20~%0AMissing%20closing%20')'%20in%20expression.%0AAt%20line%3A1%20char%3A185%0A%2B%20...%20%24Packages%3D%20Get-AllPackages%20foreach%20(%24SinglePack%20in%20%24Packages)%20%7B%20Write%20...%0A%2B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20~%0AUnexpected%20token%20')'%20in%20expression%20or%20statement.%0AAt%20line%3A1%20char%3A394%0A%2B%20...%20tatus%3D%24packinfo.status%20%7C%20Get-Unique%20foreach%20(%24sinlgestatus%20in%20%24Status%20...%0A%2B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20~~%0AUnexpected%20token%20'in'%20in%20expression%20or%20statement.%0AAt%20line%3A1%20char%3A393%0A%2B%20...%20%20%24Status%3D%24packinfo.status%20%7C%20Get-Unique%20foreach%20(%24sinlgestatus%20in%20%24Sta%20...%0A%2B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20~%0AMissing%20closing%20')'%20in%20expression.%0AAt%20line%3A1%20char%3A187%0A%2B%20...%20ackages%3D%20Get-AllPackages%20foreach%20(%24SinglePack%20in%20%24Packages)%20%7B%20Write-H%20...%0A%2B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20~%0AMissing%20closing%20'%7D'%20in%20statement%20block%20or%20type%20definition.%0AAt%20line%3A1%20char%3A404%0A%2B%20...%20ckinfo.status%20%7C%20Get-Unique%20foreach%20(%24sinlgestatus%20in%20%24Status)%7B%20Write-%20...%0A%2B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20~%0AUnexpected%20token%20')'%20in%20expression%20or%20statement.%0AAt%20line%3A1%20char%3A593%0A%2B%20...%20inlgestatus%7D)).status.count%20%2F%20(%24packinfo.Count%20-4)).tostring(%22P%22)%20%7D%20%7D%0A%2B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20~%0AUnexpected%20token%20'%7D'%20in%20expression%20or%20statement.%0A%20%20%20%20%2B%20CategoryInfo%20%20%20%20%20%20%20%20%20%20%3A%20ParserError%3A%20(%3A)%20%5B%5D%2C%20ParseException%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1815848%22%20slang%3D%22en-US%22%3ERe%3A%20Calculate%20Percent%20on%20Compliance%20SCCM%20Powershell%20by%20Device%20collection%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1815848%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F790105%22%20target%3D%22_blank%22%3E%40farismalaeb%3C%2FA%3E%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3ETried%20it%20again%20and%20Thanks%20Faris.%20This%20works.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHow%20can%20I%20limit%20this%20to%20only%20a%20specific%20Deployment%20ID%3F%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3EHow%20could%20I%20run%20this%20against%20my%20list%20of%20Device%20Collection%20Names%20perhaps%20from%20a%20txt%20file%3F%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

 

I have a function that pulls compliance status of a software update deployment (assignment ID). I want to configure this to calculate percent of the status types (Success, Error, In Progress, Unknown) and I would also like to pull compliance status based on device collection name instead of the deployment ID as it is shown below.

 

What I want to accomplish is automatically take a list of device collection names and run a software update deployment which organizes each collection by compliance percent (for each status), and then receive it by email every morning. 

 

I have several locations based on device collection, and I want to be able to differentiate which locations and devices are the problematic ones. 

 

This method makes tracking and reporting much easier and SCCM console will not have to be launched each individual time to get reporting. 

 

 

function Get-SCCMSoftwareUpdateStatus {

 

    [CmdletBinding()]

 

    param(

        [Parameter()]

        [switch]  $DeploymentIDFromGUI,

 

        [Parameter(Mandatory = $false)]

        [Alias('ID', 'AssignmentID')]

        [string]   $DeploymentID,

         

        [Parameter(Mandatory = $false)]

        [ValidateSet('Success', 'InProgress', 'Error', 'Unknown')]

        [Alias('Filter')]

        [string]  $Status

 

 

    )

 

    BEGIN {

        $Site_Code   = 'ABC'

        $Site_Server = 'SYSTEMCENTERSERVERNAME'

        $HasErrors   = $False

 

        if ($Status -eq 'Success') {

            $StatusType = 1

        }

 

        if ($Status -eq 'InProgress') {

            $StatusType = 2

        }

 

        if ($Status -eq 'Unknown') {

            $StatusType = 4

        }

 

        if ($Status -eq 'Error') {

            $StatusType = 5

        }

 

    }

 

    PROCESS {

        try {

            if ($DeploymentID -and $DeploymentIDFromGUI) {

                Write-Error "Select the DeploymentIDFromGUI or DeploymentID Parameter. Not Both"

                $HasErrors   = $True

                throw

            }

 

            if ($DeploymentIDFromGUI) {

                $ShellLocation = Get-Location

                Import-Module (Join-Path $(Split-Path $env:SMS_ADMIN_UI_PATH) ConfigurationManager.psd1)

                 

                #Checking to see if module has been imported. If not abort.

                if (Get-Module ConfigurationManager) {

                        Set-Location "$($Site_Code):\"

                        $DeploymentID = Get-CMSoftwareUpdateDeployment | select AssignmentID, AssignmentName | Out-GridView -OutputMode Single -Title "Select a Deployment and Click OK" | Select -ExpandProperty AssignmentID

                        Set-Location $ShellLocation

                    } else {

                        Write-Error "The SCCM Module wasn't imported successfully. Aborting."

                        $HasErrors   = $True

                        throw

                }

            }

 

            if ($DeploymentID) {

                    $DeploymentNameWithID = Get-WMIObject -ComputerName $Site_Server -Namespace root\sms\site_$Site_Code -class SMS_SUMDeploymentAssetDetails -Filter "AssignmentID = $DeploymentID" | select AssignmentID, AssignmentName

                    $DeploymentName = $DeploymentNameWithID.AssignmentName | select -Unique

                } else {

                    Write-Error "A Deployment ID was not specified. Aborting."

                    $HasErrors   = $True

                    throw  

            }

 

            if ($Status) {

                   $Output = Get-WMIObject -ComputerName $Site_Server -Namespace root\sms\site_$Site_Code -class SMS_SUMDeploymentAssetDetails -Filter "AssignmentID = $DeploymentID and StatusType = $StatusType" | `

                    select DeviceName, CollectionName, @{Name = 'StatusTime'; Expression = {$_.ConvertToDateTime($_.StatusTime) }}, @{Name = 'Status' ; Expression = {if ($_.StatusType -eq 1) {'Success'} elseif ($_.StatusType -eq 2) {'InProgress'} elseif ($_.StatusType -eq 5) {'Error'} elseif ($_.StatusType -eq 4) {'Unknown'}  }}

 

                } else {      

                    $Output = Get-WMIObject -ComputerName $Site_Server -Namespace root\sms\site_$Site_Code -class SMS_SUMDeploymentAssetDetails -Filter "AssignmentID = $DeploymentID" | `

                    select DeviceName, CollectionName, @{Name = 'StatusTime'; Expression = {$_.ConvertToDateTime($_.StatusTime) }}, @{Name = 'Status' ; Expression = {if ($_.StatusType -eq 1) {'Success'} elseif ($_.StatusType -eq 2) {'InProgress'} elseif ($_.StatusType -eq 5) {'Error'} elseif ($_.StatusType -eq 4) {'Unknown'}  }}

            }

 

            if (-not $Output) {

                Write-Error "A Deployment with ID: $($DeploymentID) is not valid. Aborting"

                $HasErrors   = $True

                throw

                 

            }

 

        } catch {

             

         

        } finally {

            if (($HasErrors -eq $false) -and ($Output)) {

                Write-Output ""

                Write-Output "Deployment Name: $DeploymentName"

                Write-Output "Deployment ID:   $DeploymentID"

                Write-Output ""

                Write-Output $Output | Sort-Object Status

            }

        }

    }

 

    END {}

 

}

10 Replies

@NAN2019 

Hi,

I had a small question just to confirm that I understand your question, so what you need is to get the result for all the deployment packages which listed in the following line

$DeploymentID = Get-CMSoftwareUpdateDeployment | select AssignmentID, AssignmentName | Out-GridView -OutputMode Single -Title "Select a Deployment and Click OK" | Select -ExpandProperty AssignmentID

 and get the percentage of how many deployment was success, failure ...etc

so the output will look like

Success: 40%

Error: 2%

Unknown: 50%

and so on, Yes?!

@farismalaeb 

 

1) Yes. I would like to show a clear percentage of each status (for example: Success 12% , 40% failed), for the Software update deployment. 

 

2) The 2nd request was to take the specific software update deployment and run it against device collection names. Maybe the device collection could either be in a for-each statement or if its possible to take the device collection name itself and do it. So in a sense I would have: 

 

Chicago - 75% success, 25% failed, 0% In progress, 0% failed

Cleveland - 25% success, 25% failed, 50% In progress, 0% failed

Houston - 75% success, 25% failed, 0% In progress, 0% failed

Miami - 0% success, 25% failed, 25% In progress, 50% failed

 

And I would like it to be in a csv as well as in the txt body of an email sent every morning. 

@NAN2019 

 

I wrote a quick update for script, review the change and test it, I don't have a big SCCM env, but this seems to be as you want.

Function Get-AllPackages{
$AllPack = Get-CMSoftwareUpdateDeployment | select AssignmentID, AssignmentName
return $AllPack
} 

$Packages= Get-AllPackages

foreach ($SinglePack in $Packages) {
Write-Host "--------------"
    Write-Host $SinglePack.AssignmentName
    $packinfo=Get-SCCMSoftwareUpdateStatus -DeploymentID $SinglePack.AssignmentID 
        $Status=$packinfo.status | Get-Unique
        foreach ($sinlgestatus in $Status){
        Write-Host "The Status of $($sinlgestatus) for $($SinglePack.AssignmentName)" 
            ((($packinfo | where {$_.status -like $sinlgestatus})).status.count / ($packinfo.Count -4)).tostring("P")
        

            }
} 

 

There is no change on the main function, I added extra function and some foreach loop to get the status. 

Hope it helps

 

 

---------------

If the above reply answers your question, please don't forget to click on Best Response.

 

Here is what I get. See error output below. 

So seems like this grabs all assignment ID’s, which would be every software update deployment. May be too much data even if I get is working. 

How about a specific Assignment ID?

 

At line:1 char:173
+ ... $AllPack } $Packages= Get-AllPackages foreach ($SinglePack in $Packag ...
+                                                                ~~
Unexpected token 'in' in expression or statement.
At line:1 char:172
+ ... rn $AllPack } $Packages= Get-AllPackages foreach ($SinglePack in $Pac ...
+                                                                  ~
Missing closing ')' in expression.
At line:1 char:185
+ ... $Packages= Get-AllPackages foreach ($SinglePack in $Packages) { Write ...
+                                                                 ~
Unexpected token ')' in expression or statement.
At line:1 char:394
+ ... tatus=$packinfo.status | Get-Unique foreach ($sinlgestatus in $Status ...
+                                                                ~~
Unexpected token 'in' in expression or statement.
At line:1 char:393
+ ...  $Status=$packinfo.status | Get-Unique foreach ($sinlgestatus in $Sta ...
+                                                                  ~
Missing closing ')' in expression.
At line:1 char:187
+ ... ackages= Get-AllPackages foreach ($SinglePack in $Packages) { Write-H ...
+                                                                 ~
Missing closing '}' in statement block or type definition.
At line:1 char:404
+ ... ckinfo.status | Get-Unique foreach ($sinlgestatus in $Status){ Write- ...
+                                                                 ~
Unexpected token ')' in expression or statement.
At line:1 char:593
+ ... inlgestatus})).status.count / ($packinfo.Count -4)).tostring("P") } }
+                                                                         ~
Unexpected token '}' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParseException

 

@farismalaeb 

Tried it again and Thanks Faris. This works.

 

How can I limit this to only a specific Deployment ID? 

How could I run this against my list of Device Collection Names perhaps from a txt file? 

 

 

@NAN2019 

For the first question you can add a parameter to your script SinlgeDeploymentID, and check if the value is present the parse this value, otherwise do it all :)

I did this

NOTE: I try to make the script as simple as possible to make it easier for others too.

Add this parameter on the top of your script

[CmdletBinding()]
param(
$GetonlyOne
)

in the script body add

if ($GetonlyOne -notlike $null){
Get-SCCMSoftwareUpdateStatus -DeploymentID $GetonlyOne
return
}

For the second one, its just like the first one but change the filter to match the collection Name you want

 

 

 

--------------------------------------

Thanks

 

If this answer fit your question, please mark this as Best Response and give Like :)

@farismalaeb 
thanks. 

Where does my specific Assignment ID number go or how should it fit within your script above?

 
Can you please show me an example of one? 

Also how would my List of device collection Names fit into your script if they are being pulled from a text file? 

@NAN2019 

I did another small update to provide a better output for a single Assignment ID

if ($GetonlyOne -notlike $null){

 Write-Host $SinglePack.AssignmentName
    $packinfo=Get-SCCMSoftwareUpdateStatus -DeploymentID $GetonlyOne
        $Status=$packinfo.status | Get-Unique
        foreach ($sinlgestatus in $Status){
        Write-Host "The Status of $($sinlgestatus) for $($GetonlyOne)" 
            ((($packinfo | where {$_.status -like $sinlgestatus})).status.count / ($packinfo.Count -4)).tostring("P")
        

            }
return
}

$Packages= Get-AllPackages

foreach ($SinglePack in $Packages) {
Write-Host "--------------"
    Write-Host $SinglePack.AssignmentName
    $packinfo=Get-SCCMSoftwareUpdateStatus -DeploymentID $SinglePack.AssignmentID 
        $Status=$packinfo.status | Get-Unique
        foreach ($sinlgestatus in $Status){
        Write-Host "The Status of $($sinlgestatus) for $($SinglePack.AssignmentName)" 
         ((($packinfo | where {$_.status -like $sinlgestatus})).status.count / ($packinfo.Count -4)).tostring("P")
        

            }
} 

 The call should be like this

.\ScriptName -GetonlyOne 16777338

and the output should be similar to this

WindowsServer 2016_2_2020-10-15 17:03:49
The Status of InProgress for 16777338
9.09 %
The Status of Success for 16777338
90.91 %

 

For the second one, I really did not understand how you want to fit the Collection Name here. can you explain a requirement to understand it.

 

@farismalaeb 

Thanks Faris. For some reason your Original script is still pulling all deployments. Still not limiting it to one deployment. I Have the new code in another Powershell file. I run your above command with ID and it still pulls all assignments. 

Any ideas? 

For Device collection what I would like to do is pull the compliance status for one Assignment ID but for a list of device collections Inside a text file. So basically if I can take that Assignment ID and have it check all devices (Likely from SCCM’s database) and then show a percent. For example So again: 

 

Chicago Devices.... Success 80% Error 20% 

Los Angeles Devices ... Success 15% Error 85% 

Denver Devices .... In Progress 50% Error 50% 

Cleveland Devices And so on... 

@NAN2019 

If you are calling the script without passing the

-GetonlyOne

parameter with its value (which you can get from the following line)

Get-CMSoftwareUpdateDeployment | select AssignmentID, AssignmentName | Out-GridView -OutputMode Single -Title "Select a Deployment and Click OK" | Select -ExpandProperty AssignmentID

then it will get all the software deployment package with their overall status, depend on what status is available in the Deploymentpackage state.
Can you please share the screenshot of the output you are getting