Unable to Get Deployment Status of Devices in SCCM via PowerShell

I have created a powershell script that checks a Deployment ID in sccm and then pulls all the members in the deployment and checks the deployment status for the members.
The script is able to pull the members, however, it cannot pull the Deployment Status for any of the members that it needs to check through. If possible, I would like to avoid using SQL. I just need to pull a huge report once a day that I can use to compare to another. However, I cannot figure out how to pull the Deployment Status.

    # Import SCCM module
Import-Module ($Env:SMS_ADMIN_UI_PATH.Substring(0,$Env:SMS_ADMIN_UI_PATH.Length-5) + 'ConfigurationManager.psd1')
# Change directory to the SCCM site code
cd "ABC:"
# Define the deployment ID
$deploymentID = "{B4901AE9-8501-4C32-B5BB-7AC098765B63}"
# Define the script directory and date-based folder
$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path
$date = Get-Date -Format "MM.dd.yyyy"
$childFolder = "$ScriptDir$date"
New-Item -ItemType Directory -Path $childFolder -Force
# Define the output CSV path
$csvPath = "$childFolderDeploymentStatus-$date.csv"
# Create CSV with custom column names
$headers = [PSCustomObject]@{
   "Member Name" = $null
   "Deployment Status" = $null
}
$headers | Export-Csv -Path $csvPath -NoTypeInformation
Write-Host "CSV file created with custom column names at $csvPath"
# Retrieve deployment status
$results = @()
$deployments = Get-CMDeployment | Where-Object { $_.DeploymentID -eq $deploymentID }
# Debugging step to print out the retrieved deployments
Write-Host "Retrieved deployments:"
$deployments | Format-Table -AutoSize
foreach ($deployment in $deployments) {
   $devices = Get-CMDevice -CollectionID $deployment.CollectionID
   foreach ($device in $devices) {
       # Debugging step to print out the device name
       Write-Host "Processing device: $($device.Name)"
       # Retrieve the status for each device using case-insensitive comparison
       $status = Get-CMDeploymentStatus -DeploymentID $deploymentID | Where-Object {
           $_.ResourceName -ieq $device.Name  # Case-insensitive comparison
       }
       if ($status) {
           # If status is found, output it
           Write-Host "Status for device $($device.Name): $($status.StatusType)"
           $result = [PSCustomObject]@{
               "Member Name" = $device.Name
               "Deployment Status" = $status.StatusType
           }
       } else {
           # If no status is found, mark it as "Unknown"
           Write-Host "No status found for device $($device.Name). Marking as Unknown."
           $result = [PSCustomObject]@{
               "Member Name" = $device.Name
               "Deployment Status" = "Unknown"
           }
       }
       # Add the result to the results array
       $results += $result
   }
}
# Debugging step to print out the results before exporting
Write-Host "Results to be exported:"
$results | Format-Table -AutoSize
# Export deployment status to CSV
$results | Export-Csv -Path $csvPath -NoTypeInformation -Append
Write-Host "Deployment status exported to $csvPath"
# Open the CSV file
Invoke-Item -Path $csvPath
# Pause to keep the window open
Read-Host -Prompt "Press Enter to exit"

3

Get-CMDeploymentStatus does not have a Property ResourceName that represents a device. In fact it has no info about devices at all.
What you can do is pipe its returned object into Get-CMDeploymentStatusDetails to get that information. This will already be an array of device statusinfos so the whole matching against the devices you got in a loop is not necessary. So it would look a bit like this:

$status = Get-CMDeploymentStatus -DeploymentID $deploymentID | Get-CMDeploymentStatusDetails
foreach($s in $status) {
    Write-Host "Status for device $($s.DeviceName): $($s.StatusType) ($($s.StatusDescription))"
}

You don’t even have to really check for unknown. It would just be StatusType 4 (not a missing status). Also note the StatusDescription can contain more details than the StatusType (“executed successfully”, and “no need to rerun” both would be 1 e.g.)

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật