Skip to content

Instantly share code, notes, and snippets.

@Graham-Beer
Created November 5, 2016 14:23
Show Gist options
  • Save Graham-Beer/4c66ceb5340f85a2acf664be466d8b63 to your computer and use it in GitHub Desktop.
Save Graham-Beer/4c66ceb5340f85a2acf664be466d8b63 to your computer and use it in GitHub Desktop.
.Synopsis
Get deployment status of application
.DESCRIPTION
By querying the SCCM WMI class of "SMS_AppDeploymentAssetDetails", can obtain the status of a deployment.
Adding the application name and the collection of which the application was targeted, status results can be obtained.
A filter is set for the 5 status results which the MSDN documentation stats are avaiable.
.LINK
Please see 'https://msdn.microsoft.com/en-us/library/hh948459.aspx' for the class details of "SMS_AppDeploymentAssetDetails"
.EXAMPLES
5 examples available:
Get-DeploymentStatus -AppName 'Name of Application' -Collection 'Targeted collection of deployment' -Status Success
Get-DeploymentStatus -AppName 'Name of Application' -Collection 'Targeted collection of deployment' -Status InProgress
Get-DeploymentStatus -AppName 'Name of Application' -Collection 'Targeted collection of deployment' -Status RequirementsNotMet
Get-DeploymentStatus -AppName 'Name of Application' -Collection 'Targeted collection of deployment' -Status Unknown
Get-DeploymentStatus -AppName 'Name of Application' -Collection 'Targeted collection of deployment' -Status error
.CREATOR
By Graham Beer
.VERSION
1.0
#>
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_***'
ClassName = 'SMS_AppDeploymentAssetDetails'
Filter = "AppName like '$AppName' and CollectionName like '$Collection'"
}
#Application Status table
$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 AppName,Machinename,
@{Name="StatusOfApplication";Expression={$AppStatusTypeTable["$($PSItem.AppStatusType)"]}} |
where {$PSItem.StatusOfApplication -eq "$status"} -OutVariable Countcheck
#If 0 count display a message
if([int]($countcheck).count-le 0){write-host -foreground Cyan "No Data found with the Status of `"$status"" "}
}#End Process
}#End of Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment