Import eines Computers in Configuration Manager 2007 / 2012

Nur ein ganz kurzer Artikel:

Mit diesem Skript könnt ihr einen Computer in eure Microsoft System Center Configuration Manager-Umgebung importieren.

 #####
 # Function: Import-ConfigMgr
 # This function imports a given client into a defined collection.
 # Ersteller: David O'Brien
 # Erstellt am: 14.07.2011
 #####
 Function Import-ConfigMgr
 {
 ### Define variables to import the client to ConfigMgr
 $strTargetComputer = $computername
 $strTargetMac = $computerMAC
  
 ### Which collection should the client be imported to?
 $strTargetCollection = 'Install ' + $computerOS # in my environment a Client automatically gets a machine variable $computerOS
  
 ### Load Variables
 $strSite = "Site_LAB"
  
 # Create computer in ConfigMgr
 $strColon = ":"
 $Class = "SMS_Site"
 $Method = "ImportMachineEntry"
 $MC = [WmiClass]"\\.\ROOT\SMS\$strSite$strColon$Class"
 $InParams = $mc.psbase.GetMethodParameters($Method)
 $InParams.MACAddress = $strTargetMac
 $InParams.NetbiosName = $strTargetComputer
 $InParams.OverwriteExistingRecord = $true
 $inparams.PSBase.properties | select name,Value | Format-Table
 $objCMComputer = $mc.PSBase.InvokeMethod($Method, $inParams, $Null)
  
  
 # Create Collection Rule Direct
 $Class = "SMS_CollectionRuleDirect"
 $objColRuledirect = [WmiClass]"\\$Computer\ROOT\SMS\$strSite$strColon$Class"
 $objColRuleDirect.psbase.properties["ResourceClassName"].value = "SMS_R_System"
 $objColRuleDirect.psbase.properties["ResourceID"].value = $objCMComputer.resourceID
  
  
 # Target Collection connection
 $Collection = gwmi -computer $computer -namespace "root\sms\$strSite" -class "SMS_Collection"
 $PoshCollec = $collection | where{$_.Name -eq "$strTargetCollection"}
  
  
 # Add Computer to Target Collection
 $Class = "SMS_Collection"
 $Method = "AddMembershipRule"
 $CollectionID = $PoshCollec.CollectionID
 $filter="CollectionID = '$CollectionID'"
 $MC = Get-WmiObject $class -computer $Computer -Namespace "ROOT\SMS\$strSite" -filter $filter
 $InParams = $mc.psbase.GetMethodParameters($Method)
 $InParams.collectionRule = $objColRuledirect
  
 $inparams.PSBase.properties | select name,Value | Format-Table
 $R = $mc.PSBase.InvokeMethod($Method, $inParams, $Null)
 }

Das Skript muss auf einem ConfigMgr-Management Point ausgeführt werden.

Fragen? Her damit! Wie immer hier oder auf Twitter: @david_obrien