How to use Collection Variables outside of Task-Sequences
Out of the box, Collection and Device Variables are only usable from within Task-Sequences. To get the Variables outside of Task-Sequences, you can install an additional WMI Provider (https://gallery.technet.microsoft.com/ConfigMgr-Collection-1650d5bc) that provides the Variables and Values in a separate WMI Class (root\ccm\clientsdk:EXT_CollectionVariables )
Example to get all Variables assigned to the local device:
Get-WMIObject -Namespace 'root\ccm\clientsdk' -Class 'EXT_CollectionVariables'
Example to get the value of a specific Variable
(Get-WMIObject -Namespace 'root\ccm\clientsdk' -Class 'EXT_CollectionVariables' -Filter "Name='Country'").Value
By using the WMI Provider, you can now use ConfigMgr Variables in PowerShell installation Scripts…
Note: The WMI Provider is as is without support or warranty; .NET Framework 4.5 is a prerequisite