Add computer variable

Feb 7, 2011 at 10:39 AM

Hey

 

 Maybe another good idea to add posibility of adding computer variable. That would solve a major number of problems during OSD and would give a great field of possibilities.

Feb 14, 2011 at 12:24 PM

I agree, it would be very helpful.

Mar 11, 2011 at 1:34 PM

What do you mean by "adding computer variable"?

Coordinator
Mar 11, 2011 at 4:17 PM

config MGr allows to set Variables for e.g. computers and collections. If such a variable is set on a collection/and or computer it will be available as variable/property when the task sequence is executed. You could have a look on http://myitforum.com/cs2/blogs/maikkoster/archive/2010/10/12/automatically-remove-computers-from-a-collection-and-reset-the-last-pxe-advertisement-flag-after-a-deployment-has-finished.aspx where I use a collection variable to remove computers from the collection after the task sequence has finished.

Regards

Maik

Mar 11, 2011 at 4:53 PM

Thats what I assumed he/she meant :)

I use variables in a Task Sequence combined with TS conditions to affect what AD Group a computer object will be added to i.e. If its a laptop, add it to AD Group "Its a Laptop" and if its a desktop, add it to "Its a Desktop" using a little script that uses the webservice :)

Mar 14, 2011 at 5:53 PM

Hi Maik, 

I would love to see this functionality added into the Web Service.  We are currently looking into performing automated VM provisioning and need a way to create custom variables for computers (i.e. PC Name, OS, Role, AV Management Server, etc.) as part of the provisioning process.  Any chance this is something in the works or could be handled by the Web Service?

Mar 20, 2011 at 7:58 PM

Well in Config Mgr SDK is shown how to do it. But now the question how to make it working from a Web Service :D

Jan 31, 2013 at 10:17 AM
That would be awesome, if the webservice would allow to add computer and collection tasksequence variables. I would use that for a webinterface that allows to provisioning machines KeyboardLayout, Timezone, UILanguage, BitlockerPin, etc...
Jan 31, 2013 at 10:23 AM
There's some powershell code i once made
Function SCCM-GetComputerVariables
{
param(        
        [parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true,HelpMessage="Primary Site Server name" )]
        [alias('SiteServer','__Server', 'ServerName')]
        [string]
        $Server,

        [parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true,HelpMessage="Primary Site Servers SiteCode")]
        [alias('CentralSiteCode','__SiteCode')]
        [string]
        $SiteCode,       
        
        [parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, HelpMessage="Computer Name")]
        [alias('NetBiosName','Name', '__Name')]
        [string]
        $ComputerName)



        
    $query = 'SELECT * FROM SMS_R_System WHERE NetBiosName = "{0}" And Active = 1' -f $ComputerName
    $Computer = Get-WmiObject  -ComputerName $Server -Namespace "root\sms\site_$SiteCode"  -Query $query
   
    $objMachineSettings = Get-WmiObject -computername “$Server” -namespace “root\sms\site_$SiteCode” -class “sms_machinesettings” | where{$_.ResourceID -eq $Computer.ResourceID}
    $objMachineSettings.get()

    $variables = $objMachineSettings.MachineVariables
    
    Return $variables

}

Function SCCM-SetComputerVariable
{
param(        
        [parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true,HelpMessage="Primary Site Server name" )]
        [alias('SiteServer','__Server', 'ServerName')]
        [string]
        $Server,

        [parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true,HelpMessage="Primary Site Servers SiteCode")]
        [alias('CentralSiteCode','__SiteCode')]
        [string]
        $SiteCode,       
        
        [parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, HelpMessage="Computer Name")]
        [alias('NetBiosName','Name', '__Name')]
        [string]
        $ComputerName,
                
        [parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, HelpMessage="SCCM Variable")]
        [alias('Vars','Var', '__SCCMVariables')]
        #[array]
        $VariablesHash
        
        )


        $query = 'SELECT * FROM SMS_R_System WHERE NetBiosName = "{0}"' -f $ComputerName
        $Computer = Get-WmiObject  -ComputerName $Server -Namespace "root\sms\site_$SiteCode" -Query $query
   
        $ResourceID  = $Computer.ResourceID

        #todo Resource ID ???

        $MachineSettings = Get-WMIObject -ComputerName $Server -Namespace "Root\SMS\Site_$SiteCode" -class "SMS_MachineSettings" | where {$_.CollectionID -eq $CollectionID}
        # Create new instance of MachineSettings if not found
        If (!$MachineSettings) {
            $NewMachineSettingsInstance = $([wmiclass]"\\$Server\Root\SMS\Site_$($SiteCode):SMS_MachineSettings").CreateInstance()
            $NewMachineSettingsInstance.ResourceID = $ResourceID
            $NewMachineSettingsInstance.SourceSite = $sitename
            $NewMachineSettingsInstance.LocaleID = 1033
            $NewMachineSettingsInstance.psbase
            $NewMachineSettingsInstance.psbase.Put
            $MachineSettings += $NewMachineSettingsInstance
        }

        ForEach ($Machine in $MachineSettings) {
           $Machine.psbase.Get
           $MachineVariables = $Machine.MachineVariables
            
           ForEach ($key in $VariablesHash.keys) {
               $ConfigMgrVar = $([wmiclass]"Root\SMS\Site_$($sitename):SMS_MachineVariable").CreateInstance()
               $ConfigMgrVar.Name = $key
               $ConfigMgrVar.Value = $VariablesHash[$key]
               #$ConfigMgrVar.IsMasked = [Int]$($ConfigMgrMachineVariable.IsMasked)
        
               [System.Management.ManagementBaseObject[]]$MachineVariables += $ConfigMgrVar
           }
           $Machine.MachineVariables = $MachineVariables
           $Machine.psbase.Put()
       }
    
}