Skip to main content

PowerShell + SCCM 2012 : Get-DPContent (Get all the Packages stored on a DP)

This week when came back from office , saw this tweet from Adam Bertram:



It got me curious how to Script this, I had written a Script in past to remove packages from the DP. So let's try out this scenario.

The class to query is the SMS_DistributionPoint class and the property to be used for filtering is ServerNALPath. My Lab has only one DP named "DexSCCM" so gonna use that in the filter. Note the WQL operator used here for filtering is LIKE not '='.


001
Get-CimInstance -ClassName SMS_DistributionPoint -Filter "ServerNALPAth LIKE '%DexSCCM%'" -ComputerName dexsccm -Namespace Root\SMS\Site_DEX


This will give you a bunch of objects back , below is one of the objects screenshot:




Note - Please take a moment to go to the MSDN documentation of the SMS_DistributionPoint WMI Class and pay attention to the ObjectTypeID, SecureObjectID and PackageID properties.

From the above Objects I can get the PackageID or SecureObjectID and get an instance of the appropriate Object based on ObjectTypeID. :)

For the above Screenshot the ObjectTypeID is 2 which as per MSDN documentation says it corresponds to a SMS_Package class so let me get the instance of SMS_Package having the PackageID "DEX00001"



PS> Get-CimInstance -ClassName SMS_Package -Filter 'PackageID="DEX00001"' -ComputerName dexsccm -Namespace Root\SMS\Site
_DEX


ActionInProgress               : 0
AlternateContentProviders      :
Description                    : This package is created during installation.
ExtendedData                   :
ExtendedDataSize               : 0
ForcedDisconnectDelay          : 5
ForcedDisconnectEnabled        : False
ForcedDisconnectNumRetries     : 2
Icon                           :
IconSize                       : 0
IgnoreAddressSchedule          : False
ISVData                        :
ISVDataSize                    : 0
IsVersionCompatible            : True
Language                       :
LastRefreshTime                : 2/9/2014 2:23:00 PM
LocalizedCategoryInstanceNames : {}
Manufacturer                   : Microsoft Corporation
MIFFilename                    :
MIFName                        :
MIFPublisher                   :
MIFVersion                     :
Name                           : User State Migration Tool for Windows 8
NumOfPrograms                  : 0
PackageID                      : DEX00001
PackageSize                    : 48381
PackageType                    : 0
PkgFlags                       : 0
PkgSourceFlag                  : 2
PkgSourcePath                  : C:\Program Files (x86)\Windows Kits\8.1\Assessment and Deployment Kit\User State
                                 Migration Tool
PreferredAddressType           :
Priority                       : 2
RefreshPkgSourceFlag           : False
RefreshSchedule                :
SecuredScopeNames              : {Default}
SedoObjectVersion              : FF4B4436-5124-4875-ADB3-168BF444068C
ShareName                      :
ShareType                      : 1
SourceDate                     : 2/9/2014 2:06:15 PM
SourceSite                     : DEX
SourceVersion                  : 1
StoredPkgPath                  :
StoredPkgVersion               : 1
Version                        : 6.3.9431.0
DefaultImageFlags              : 2
IsPredefinedPackage            : False
TransformAnalysisDate          : 1/1/1980 5:30:00 AM
TransformReadiness             : 0
PSComputerName                 : dexsccm


It works ! Got the Object back and following this approach can get the Objects stored on the DP.

But there is a small catch when the ObjectTypeID is 31 (SMS_Application) then we can't use the PackageID as a filter with the SMS_Application Class because it is a lazy property. If you don't believe me go ahead and try it (already did). So we have to use another property ModelName to filter.

To assist on this wrote a small Function called Get-DPContent (download it) which allows you to specify a DPName and the ObjectType (application, package, image etc) you want report of being stored in a DP. One can modify the Function to include all details for the Objects but I was just looking for the names of the packages, applications etc. Below is how you use it (once you have it dot sourced)


PS C:\> get-DPContent -DPname dexsccm  

DP                                        ObjectType                               Package                                  PackageID                               
--                                        ----------                               -------                                  ---------                               
dexsccm                                   Package                                  User State Migration Tool for Windows 8  DEX00001                                
dexsccm                                   Package                                  Configuration Manager Client Package     DEX00002                                


By default it only looks for Packages
One has to specify the ObjectType in order to look for Applications :


PS> Get-DPContent -DPname dexsccm -ObjectType Application -SCCMServer dexsccm

DP                            ObjectType                    Application                   Description
--                            ----------                    -----------                   -----------
dexsccm                       Application                   7-Zip                         For 64-bit machines only
dexsccm                       Application                   PowerShell Community Exten... PSCX 3.1
dexsccm                       Application                   Quest Active Roles Managme... Quest Snapin for AD Admins...
dexsccm                       Application                   PowerShell Set PageFile       The Script will set the  P...
dexsccm                       Application                   NotePad++                     Alternative to Notepad


Hope this helps someone, trying to generate a list of Packages on a DP :)
This can be modified to work with SCCM 2007 too but seriously are you still running that :P
Cheers !

Resources:

Technet Gallery: Get list of Packages stored on a DP in ConfigMgr/ SCCM 2012
http://gallery.technet.microsoft.com/Get-list-of-Packages-35208e83/



SMS_Distribution WMI Class
http://msdn.microsoft.com/en-us/library/hh949735.aspx




Popular posts from this blog

Test connectivity via a specific network interface

Recently while working on a Private cloud implementation, I came across a scenario where I needed to test connectivity of a node to the AD/DNS via multiple network adapters.  Many of us would know that having multiple network routes is usually done to take care of redundancy. So that if a network adapter goes down, one can use the other network interface to reach out to the node. In order to make it easy for everyone to follow along, below is an analogy for the above scenario: My laptop has multiple network adapters (say Wi-Fi and Ethernet) connected to the same network. Now how do I test connectivity to a Server on the network only over say Wi-Fi network adapter?

PowerShell + SCCM : Run CM cmdlets remotely

Today I saw a tweet about using implicit remoting to load the Configuration Manager on my machine by Justin Mathews . It caught my eye as I have never really tried it, but theoretically it can be done. Note - The second tweet says "Cannot find a provider with the name CMSite", resolution to which is in the Troubleshooting section at the end.

PowerShell : Trust network share to load modules & ps1

Problem Do you have a central network share, where you store all the scripts or PowerShell modules ? What happens if you try to run the script from a network share ? or if you have scripts (local) which invoke scripts or import PowerShell modules stored on this network share ? Well you would see a security warning like below (Note - I have set execution policy as 'Unrestricted' not 'bypass' here): Run a .ps1 from the network share Well this is a similar warning, which you get when you download scripts from Internet. As the message says run Unblock-File cmdlet to unblock the script and then run it, let's try it.