Forum Discussion
Calculate Percent on Compliance SCCM Powershell by Device collection
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.
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.
- NAN2019Oct 25, 2020Copper Contributor
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?- farismalaebOct 25, 2020Iron Contributor
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 🙂
- NAN2019Oct 25, 2020Copper Contributor
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?
- NAN2019Oct 25, 2020Copper Contributor
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