Skip to content

Instantly share code, notes, and snippets.

@Graham-Beer
Created November 5, 2016 14:09
Show Gist options
  • Save Graham-Beer/9e5922ad8de7dac7a3834bbfc40bc54b to your computer and use it in GitHub Desktop.
Save Graham-Beer/9e5922ad8de7dac7a3834bbfc40bc54b to your computer and use it in GitHub Desktop.
Synopsis
Find where an application has been deployed to.
.DESCRIPTION
To determine which collection an application has been deployed to. Results will show Name of application, the deployment ID
and the collection the application has been deployed to.
.EXAMPLE
get-AppDeployedToCollection -Application 'Microsoft Office 2016'
.OUTPUTS
Application_Name DeploymentID Deployed_To_Collection
---------------- ------------ ----------------------
Microsoft Office 2016 {49B9BBF1-5D60-4633-A3DE-D43693G52921} Current_Office_Collection
.NOTES
General notes
.COMPONENT
This tool is used with SCCM. The WMI queries the SCCM Namespace and classes.
.ROLE
The role this cmdlet belongs to SCCM
.CREATOR
Graham Beer
#>
Function get-AppDeployedToCollection {
Param
(
[Parameter(Mandatory,
ValueFromPipeline=$true,
Position=1,
ParameterSetName='Define Application')]
[ValidateScript({(Get-CimInstance -Namespace Root\SMS\Site_*** -query "select * from SMS_application where LocalizedDisplayName like '$_'")})]
[string[]]$Application
)
Begin
{
$query = @{
Namespace='ROOT\SMS\Site_**'
Query="SELECT DeploymentID,TargetName,CollectionName FROM
SMS_Deploymentinfo
WHERE
SMS_Deploymentinfo.DeploymentID IN
(SELECT DeploymentID
FROM SMS_Deploymentsummary
WHERE
SMS_Deploymentsummary.SoftwareName = '$Application')" }
$AllFoundUpdates = @() #Create empty array
}#End of Begin block
process
{
#Run the WQL query
$Results = Get-CimInstance @query
if($Results.count -gt 1){Write-host -ForegroundColor yellow "`nThere are $($Results.count) instances of $($Results.TargetName[0])"}
else
{<#Say nothing!#>}
#use foreach as Application could be deployed to more than one collection
foreach ($Result in $Results){
#Create custom object
$UpdateObj=[pscustomobject]@{"Application_Name"="";"Deployed_To_Collection"="";"DeploymentID"=""}
$UpdateObj.Application_Name = $Result.TargetName
$UpdateObj.Deployed_To_Collection = $result.CollectionName
$UpdateObj.DeploymentID = $result.DeploymentID
$AllFoundUpdates += $UpdateObj #Add results to array
}
}#End of Process block
End
{
#Display results
Return $AllFoundUpdates
}#End of End block
}#End of Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment