środa, 21 grudnia 2016

Script Displaying All Deployments for a Computer Asset



    You might have a need to identify any possible deployments, that are assigned to a particular machine in SCCM. This script will create a list of such deployments and dump it into a .csv file

Usage:
 
    Save the code below to a .ps1 file. Replace the following strings:

1. SMS_Provider_Server_FQDN - replace with an FQDN of you SMS Provider server
2. root\SMS\Site_XXX - replace the XXX with your SCCM Site code

    If you wish to add additional filter you can add additional condition here (replace XXX with the pattern you want to look up):

$Deployments = (Get-WmiObject @ConnectionObj -Query "Select * From SMS_DeploymentInfo WHERE CollectionID='$($Collection.CollectionID)' AND TargetName LIKE '%XXX%'")
 
    If you want to change the output location change the directory and a file name in the last line of the script.

Additional Notes:
 
    The script is a remake of another script found on the Internet. The original idea of the script dumping User deployments to the screen was adapted to the needs of the organization.

Code:
$ConnectionObj = @{
    ComputerName = "SMS_Provider_Server_FQDN"
    NameSpace = "root\SMS\Site_XXX"
}
$Array = @()
$Computer = Get-WMIObject @ConnectionObj -Query "Select * From SMS_R_System WHERE Name = 'XXX'"
$Collections = Get-WmiObject -Class sms_fullcollectionmembership @ConnectionObj -Filter "ResourceID = '$($Computer.resourceid)'"

Foreach ($Collection in $collections)
{                 
    $Deployments = (Get-WmiObject @ConnectionObj -Query "Select * From SMS_DeploymentInfo WHERE CollectionID='$($Collection.CollectionID)'")
    Foreach ($Deploy in $Deployments)
    {
        $Properties = @{
            ComputerName = $Computer.Name
            CollectionName = $Deploy.CollectionName
            CollectionID = $Deploy.CollectionID
            DeploymentID = $Deploy.DeploymentID
            DeploymentName = $Deploy.DeploymentName
            ApplicationName = $Deploy.TargetName
            ApplicationSubName = $Deploy.TargetSubname
        }       
        $Array += $(New-Object -TypeName PSObject -prop $Properties)
    }
}
$Array | Export-CSV -NoTypeInformation "C:\Temp\Applications.csv"

Brak komentarzy:

Prześlij komentarz