Hi Everyone.
I frequently have at least 5% of machines fail on deployments and find the process of remediation to be very cumbersome in SCCM. I propose this to help others in this situation.
It creates a list of all machines without a status of 1 (success). You can direct export this with the commented out export-csv line if you wish to stop there. Excel will open this list just fine. I took it a step further to create a collection and add them all to the new collection so we can send a different "fixed" deployment to them.
$DeploymentID = "WSD206AE"
$NonSuccess = Get-CMDeploymentStatus -DeploymentId $DeploymentID | where {$_.statustype -ne 1}
$ReportObject = New-Object System.Collections.ArrayList
foreach ($statustype in $NonSuccess) {
$computerlist = $statustype | Get-CMDeploymentStatusDetails
$reportobject.AddRange(($computerlist | select devicename,statusdescription,deviceid))
}
#$ReportObject | Export-Csv c:\myreport.csv -Encoding ASCII -NoTypeInformation -Force
#Add devices to new collection
$NewCollectionName = "New Collection Name"
$AllSystems = Get-CMDeviceCollection -name "All Systems"
$NewCollection = New-CMDeviceCollection -Name $NewCollectionName -LimitingCollection $AllSystems
if ($NewCollection) {
$i = 0
foreach ($device in $ReportObject) {
write-progress -Activity "Adding Devices" -Status "$i / $($ReportObject.count) to $($NewCollection.name)" -percentcomplete ($i / $ReportObject.count * 100)
Add-CMDeviceCollectionDirectMembershipRule -CollectionId $NewCollection.CollectionID -ResourceId $device.deviceid -ea silentlycontinue
$i++
}
}
else {Write-Host "Could not create new collection ($NewCollectionName)"}