Hi, I have written this script to look at deployment status for SCCM.
All works fine, but would like to add a column at the start to count the items as it runs down.
i.e.
Count - App - Status
1 office Success
2 office Success
3 office Success
Function Get-DeploymentStatus {
[CmdletBinding()]
Param
(
#Set application name
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
[string]$AppName,
[string]$Collection,
[ValidateSet("Success", "InProgress", "RequirementsNotMet","Unknown","error")]
[String]$Status
)
Begin {
$query = @{
Namespace = 'root\SMS\site_AAC'
ClassName = 'SMS_AppDeploymentAssetDetails'
Filter = "AppName like '$AppName' and CollectionName like '$Collection'"
}
$AppStatusTypeTable = DATA {ConvertFrom-StringData @'
1 = Success
2 = InProgress
3 = RequirementsNotMet
4 = Unknown
5 = Error
'@}
}#End Begin
process {
Get-CimInstance @query |
Select-Object AppName,Machinename,
@{Name="StatusOfApplication";Expression={$AppStatusTypeTable["$($PSItem.AppStatusType)"]}} |
where {$PSItem.StatusOfApplication -eq "$status"}
}#End Process
}#End of Function
Any help would be great, banging my head against a brick wall !
If I’ve understood what you’re after, I think this will work.
Add $count = 0
to the Begin block.
Add $count++
to the Process block.
Add @{Name=“Count”;Expression={$count}}
to your Select-Object
Hi Matt,
I’ve tried that, but doesn’t count up…
Function Get-DeploymentStatus {
[CmdletBinding()]
Param
(
#Set application name
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
[string]$AppName,
[string]$Collection,
[ValidateSet("Success", "InProgress", "RequirementsNotMet","Unknown","error")]
[String]$Status
)
Begin {
$query = @{
Namespace = 'root\SMS\site_AAC'
ClassName = 'SMS_AppDeploymentAssetDetails'
Filter = "AppName like '$AppName' and CollectionName like '$Collection'"
}
$count = 0 #Set counter for 'count' column in select statement
$AppStatusTypeTable = DATA {ConvertFrom-StringData @'
1 = Success
2 = InProgress
3 = RequirementsNotMet
4 = Unknown
5 = Error
'@}
}#End Begin
process {
$count++ #post-incrementation
Get-CimInstance @query |
Select-Object @{Name="Count";Expression={$count}},
AppName,Machinename,
@{Name="StatusOfApplication";Expression={$AppStatusTypeTable["$($PSItem.AppStatusType)"]}} |
#filter out "status"
where {$PSItem.StatusOfApplication -eq "$status"}
}#End Process
}#End of Function
This is what the result looks like…
Count AppName Machinename StatusOfApplication
----- ------- ----------- -------------------
1 "PackageName" Machine01 Success
1 "PackageName" Machine-02 Success
1 "PackageName" Machine-03 Success
1 "PackageName" Machine-04 Success
1 "PackageName" Machine-05 Success
Do i need to “count” on something ?
Cracked it…
needed to set a “scope” once $Script: was put in front of the count it worked.
Function Get-DeploymentStatus {
[CmdletBinding()]
Param
(
#Set application name
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
[string]$AppName,
[string]$Collection,
[ValidateSet("Success", "InProgress", "RequirementsNotMet","Unknown","error")]
[String]$Status
)
Begin {
#Set query for 'Get-Ciminstance' search
$query = @{
Namespace = 'root\SMS\site_AAC'
ClassName = 'SMS_AppDeploymentAssetDetails'
Filter = "AppName like '$AppName' and CollectionName like '$Collection'"
}
#Set counter for 'count' column in select statement
$script:count = 1
$AppStatusTypeTable = DATA {ConvertFrom-StringData @'
1 = Success
2 = InProgress
3 = RequirementsNotMet
4 = Unknown
5 = Error
'@}
}#End Begin
process {
#Run get-ciminstance with query
Get-CimInstance @query |
Select-Object @{Name="Count";Expression={$Script:count;$Script:count++}},
AppName,Machinename,
@{Name="StatusOfApplication";Expression={$AppStatusTypeTable["$($PSItem.AppStatusType)"]}} |
#filter out "status"
where {$PSItem.StatusOfApplication -eq "$status"}
}#End Process
}#End of Function
Thanks for your help Matt.
I’ve add a “where” statement to filter on desired result (i.e. Success), is there a better way to do this ?
That’s interesting. I thought the PROCESS block would increment the counter without any fiddling.
I’m not sure if there’s a better way. I don’t have SCCM at home so I can’t test. I did wonder if you could move it to your query by adding AppStatusType=1 to your filter.