header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
How to Create a Collection Variable in Configuration Manager
Last Post 21 Jan 2010 09:35 AM by George Howarth. 8 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Not Resolved
metanUser is Offline
New Member
New Member
Posts:4
Avatar

--
20 Jan 2010 06:57 AM

    Hi,

    I read the doc but did not see how to realize it. I know this is necessary to create an array  for collect woion variables, but don't see how to inject it in sms_CollectionSettings class...
    the following doc I followed :
    http://msdn.microsoft.com/en-us/lib...44130.aspx
    sms_CollectionSettings : http://msdn.microsoft.com/en-us/lib...46203.aspx
    sms_CollectionVariable : http://msdn.microsoft.com/en-us/lib...46201.aspx

    and this my code, didnt worked (only the precedence variable is correctly set :

    $ColVarClass = [wmiclass] "\\srv01\root\sms\site_ABC:SMS_CollectionVariable"
    $myColVarClass = $ColVarClass.CreateInstance()
    $myColVarClass.Boolean = "true"
    $myColVarClass.Name = "Testxxxname"
    $myColVarClass.Value = "TestxxxValue"
    $ArrayColVar = array($myColVarClass.Boolean,$myColVarClass.Name,$myColVarClass.Value)
    trap {;continue} $myColVarClass.Put()
    $retvalColVar = $myColVarClass.Put()

    $ColSetClass = [wmiclass] "\\srv01\root\sms\site_ABC:SMS_CollectionSettings"
    $myColSetClass = $ColSetClass.CreateInstance()
    $myColSetClass.CollectionID  = "ABC000B8"
    $myColSetClass.CollectionVariablePrecedence = "7"
    $myColSetClass.CollectionVariables = $ArrayColVar

    trap {;continue} $myColSetClass.Put()
    $retvalColSetClass = $myColSetClass.Put()


    do you see what would be the correct syntax to add collection variables to my collectionID ? Thanks in advance.

    Marco Shaw (MVP)User is Offline
    Veteran Member
    Veteran Member
    Posts:1647
    Avatar

    --
    20 Jan 2010 07:05 AM
    I won't be of much help, but looking at the links you provided, this line:
    $myColVarClass.Boolean = "true"
    Should likely be:
    $myColVarClass.IsMasked = $true
    Marco

    *Microsoft MVP - Windows PowerShell
    https://mvp.support.microsoft.com/profile/Marco.Shaw
    *Co-Author - Sams Windows PowerShell Unleashed 2nd Edition
    *Blog - http://marcoshaw.blogspot.com
    metanUser is Offline
    New Member
    New Member
    Posts:4
    Avatar

    --
    20 Jan 2010 07:12 AM

    yes exact it was a mistake thanks. I modified it, but do you see what  I have to modifiy for a correct script ?

    George HowarthUser is Offline
    Basic Member
    Basic Member
    Posts:360
    Avatar

    --
    20 Jan 2010 07:55 AM
    I think this line is also a mistake:

    $ArrayColVar = array($myColVarClass.Boolean,$myColVarClass.Name,$myColVarClass.Value)

    ...should be:

    $ArrayColVar = @($myColVarClass.IsMasked,$myColVarClass.Name,$myColVarClass.Value)
    metanUser is Offline
    New Member
    New Member
    Posts:4
    Avatar

    --
    20 Jan 2010 08:36 AM
    hum thanks GWHowarth, but no changes for moment :(
    Do you see what else could be wrong, and why collection variaboes are not created..?

    In WMI explorer I see collection variables are created in SMS_collectionvariables instances, but are no displayed in sccm console...
    if you see what could be wrong or correct the code, thanks in advance...
    George HowarthUser is Offline
    Basic Member
    Basic Member
    Posts:360
    Avatar

    --
    20 Jan 2010 10:02 AM
    Unfortunately, I don't have anything to test your script with, so this is just guess work. However, I'm almost certain that this is incorrect:

    $myColSetClass.CollectionVariables = $ArrayColVar

    From the looks of it, in order to add a collection variable to collection settings, you have to use the IResultObject.SetArrayItems method. It's function signature is declared as such (C#):

    void SetArrayItems (string propertyName, List< IResultObject > value)

    Therefore, you have to create a List of type System.Collections.Generic.List, which holds values of type Microsoft.ConfigurationManagement.ManagementProvider.IResultObject to store the properties of your instantiated SMS_CollectionVariable class. This is how you would do it:

    function New-GenericList([Type] $type)
    {
    $base = [System.Collections.Generic.List``1]
    $qt = $base.MakeGenericType(@($type))
    New-Object $qt
    }

    $ArrayColVar = New-GenericList Microsoft.ConfigurationManagement.ManagementProvider.IResultObject
    $ArrayColVar.Add($myColVarClass)


    Then, once that's done, you can pass your list as a parameter to the SetArrayItems() method:

    $myColSetClass.SetArrayItems("CollectionVariables", $ArrayColVar)

    Another thing to note is that (from the looks of it) the properties in the SMS_CollectionVariables class are accessed via indexers and converted to their necessary values, not by using the dot operator:

    $myColVarClass["IsMasked"].BooleanValue = $true
    $myColVarClass["Name"].StringValue = "Testxxxname"
    $myColVarClass["Value"].StringValue = "TestxxxValue"


    Finally, the IResultObject.Put() method returns void, so there is no point in having these statements:

    $retvalColVar = $myColVarClass.Put()
    $retvalColSetClass = $myColSetClass.Put()


    So your end result looks something like this:

    trap { continue }

    function New-GenericList([Type] $type)
    {
    $base = [System.Collections.Generic.List``1]
    $qt = $base.MakeGenericType(@($type))
    New-Object $qt
    }

    $ColVarClass = [WMIClass]"\\srv01\root\sms\site_ABC:SMS_CollectionVariable"
    $myColVarClass = $ColVarClass.CreateInstance()
    $myColVarClass["IsMasked"].BooleanValue = $true
    $myColVarClass["Name"].StringValue = "Testxxxname"
    $myColVarClass["Value"].StringValue = "TestxxxValue"
    $ArrayColVar = New-GenericList Microsoft.ConfigurationManagement.ManagementProvider.IResultObject
    $ArrayColVar.Add($myColVarClass)

    $myColVarClass.Put()

    $ColSetClass = [WMIClass]"\\srv01\root\sms\site_ABC:SMS_CollectionSettings"
    $myColSetClass = $ColSetClass.CreateInstance()
    $myColSetClass["CollectionID"].StringValue = "ABC000B8"
    $myColSetClass["CollectionVariablePrecedence"].IntegerValue = "7"
    $myColSetClass.SetArrayItems("CollectionVariables", $ArrayColVar)

    $myColSetClass.Put()


    Again, I could be wrong, because I don't have anything to test this with.
    George HowarthUser is Offline
    Basic Member
    Basic Member
    Posts:360
    Avatar

    --
    20 Jan 2010 10:10 AM
    Edit 1: forgot to change your target machine to srv01 from localhost. Fixed.
    Edit 2: Used indexers with the instantiated SMS_CollectionSettings class.
    metanUser is Offline
    New Member
    New Member
    Posts:4
    Avatar

    --
    21 Jan 2010 08:14 AM
    Hi, first thanks for explanations, even if if did not work, It allow to better understdand methodology...:)
    btw, I launch the script CreateColl.ps1, replaced site values, but no changes on specific collection. Even precedence variable, which worked before with my code, is not changed :(
    The problem is the cript do not exit error codes or messages, so I really dont know what could be missing...
    and if you have not SCCM installed, it will be difficult to test for u...
    anyway if you have an idea about what could be wrong with it, I'm interested :)
    Thanks in advance and for ur work.
    George HowarthUser is Offline
    Basic Member
    Basic Member
    Posts:360
    Avatar

    --
    21 Jan 2010 09:35 AM
    Can you confirm that an instance of SMS_CollectionVariable is being made? You can do that by using Get-Member to see if there's anything there:

    $ColVarClass = [WMIClass]"\\srv01\root\sms\site_ABC:SMS_CollectionVariable"
    $myColVarClass = $ColVarClass.CreateInstance()
    $myColVarClass | Get-Member
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer