 |
|
|
How to Create a Collection Variable in Configuration Manager
|
Sort:
|
|
Prev Next |
You are not authorized to post a reply. |
|
| Author |
Messages |
 |
metan
 New Member Posts:4

 |
| 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)
 Veteran Member Posts:1647

 |
| 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 |
|
|
metan
 New Member Posts:4

 |
| 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 Howarth
 Basic Member Posts:360

 |
| 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) |
|
|
|
|
metan
 New Member Posts:4

 |
| 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 Howarth
 Basic Member Posts:360

 |
| 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 Howarth
 Basic Member Posts:360

 |
| 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. |
|
|
|
|
metan
 New Member Posts:4

 |
| 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 Howarth
 Basic Member Posts:360

 |
| 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
|
|
 |