Introduction
Before we begin
To ease your life, 2 downloads are required :- First, Download SCCM SDK here
- Download MoW WMi Explorer that will help you buil SCCM Powershell code
Let first discover SCCM namespaces. Launch wmiexplorer.ps1 on your SCCM server :
DoubleClick on a Site namespace to list the classes
' Connect
Set siteClass = connection.Get("SMS_Site")
Set inParams = siteClass.Methods_("ImportMachineEntry"). _
inParameters.SpawnInstance_()
' Add the input parameters.
inParams.Properties_.Item("MACAddress") = macAddress
inParams.Properties_.Item("NetbiosName") = netBiosName
inParams.Properties_.Item("OverwriteExistingRecord") = False
inParams.Properties_.Item("SMBIOSGUID") = smBiosGuid
' Add the computer
Set outParams = connection.ExecMethod("SMS_Site", "ImportMachineEntry", inParams)
Here comes the real deal
Let use MoW's WmiExplorer to get our answer :
Double Click on the SMS_Site Class to list all properties and methods of the class. You'll see on the right panel that there's a Method called "ImportMachineEntry"
Now Double Click on this Method. Mow's WmiExplorer is a smart tool : it buil dynamically PowerShell sample to use the method as shown below :
- MacAddress (MAC Address of the target computer)
- NetbiosName
- ...
If we use get-membere, we see that there isn't any "ImportMachineEntry" method here. This is due to the specific object output formatting of PowerShell. In order to access properties and methods of this class, we need to use the PSBASE method to have a "RAW" access on this object (more information on PSBASE here ) :
As we can see, $mc.psbase brings Methods and Properties. Now list methods :
Set inParams = siteClass.Methods_("ImportMachineEntry"). _
inParameters.SpawnInstance_()
inParams.Properties_.Item("MACAddress") = macAddress
inParams.Properties_.Item("NetbiosName") = netBiosName
inParams.Properties_.Item("OverwriteExistingRecord") = False
inParams.Properties_.Item("SMBIOSGUID") = smBiosGuid
To do the same thing in PowerShell, have a look at the Mow generated script :
$InParams.MACAddress = [string]
$InParams.NetbiosName = [string]
$InParams.OverwriteExistingRecord = [boolean]
$InParams.SMBIOSGUID = [string]
As you can see, the code is rather simple : this example just do the same thing.
We see here our 4 properties : MacAddress, NetbiosName, OverwriteExistingRecord and SMBIOSGUID, all empty. Notice that each properties Types are exposed in the definition column, and that they are all Read/Write (get;Set)
Sorting the Output of $Inparams, we see that our object's properties aren't empty anymore.
Now we need to execute our Method with the parameters. The VBScript sample said :
Set outParams = connection.ExecMethod("SMS_Site", "ImportMachineEntry", inParams)
$mc.PSBase.InvokeMethod($Method, $inParams, $Null)
Here we are ! Our Computer is properly import in SCCM. For now, only in the "All Systems" collection.
The next step in the SDK is to add this machine to a specific collection. We will explain this in the Part 2 of this discussion.
You know now how to identify the class, method and properties to accomplish SCCM task in the SDK, and convert them in PowerShell. Have Fun !
Aucun commentaire:
Enregistrer un commentaire