question

MikePlichta-1080 avatar image
0 Votes"
MikePlichta-1080 asked CB-4478 published

SCCM Export computers from failed deployment to Excel or new device collecton

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)"}
mem-cm-general
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AlexZhu-MSFT avatar image
0 Votes"
AlexZhu-MSFT answered

Hi,

It's a great pity for having missed this great thread as the tag prefix has changed from "me-cm-" to "mem-cm-". Thank you very much for sharing this useful script, which helps IT staff a lot in daily work automation.

Have a nice day!

Alex Zhu


If the response is helpful, please click "Accept Answer" and upvote it.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

CB-4478 avatar image
0 Votes"
CB-4478 answered CB-4478 published

Receiving this error when running the script.


Cannot convert argument "c", with value: "@{devicename=Obfuscated PC Name ; statusdescription=Program received;
deviceid=16789037}", for "AddRange" to type "System.Collections.ICollection": "Cannot convert the
"@{devicename=Obfuscated PC Name ; statusdescription=Program received; deviceid=16789037}" value of type
"Selected.Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine.WqlResultObject" to type
"System.Collections.ICollection"."
At line:7 char:4
+ $reportobject.AddRange(($computerlist | select devicename,statusdescription,d ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument


Cannot convert argument "c", with value: "@{devicename=Obfuscated PC Name ; statusdescription=Program failed;
deviceid=16788484}", for "AddRange" to type "System.Collections.ICollection": "Cannot convert the
"@{devicename=Obfuscated PC Name ; statusdescription=Program failed; deviceid=16788484}" value of type
"Selected.Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine.WqlResultObject" to type
"System.Collections.ICollection"."
At line:7 char:4
+ $reportobject.AddRange(($computerlist | select devicename,statusdescription,d ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.