0

I have the need to create an SCCM object/device from a running WinPE medium using PowerShell. How could one do such a thing?

A former employee of the company I am working for has created a C# Web Solution using "microsoft.configurationmanagement.managementprovider.dll" to create SCCM devices and add attributes to it. I have to migrate this function to a PowerShell Script running on WinPE.

Any input, pointers on this? Thanks in advance

1 Answer 1

0

maybe you could something like this:

# client data
$clientname = "PC01"
$mac = "00:11:22:33:44:55"

# server data
$serverhostname = "SCCMSERVER01"
$sitecode = "ABC"
$collname = "Windows_7_OSD"

# query
$collquery = Get-WmiObject -Namespace "Root\SMS\Site_$sitecode" -Class SMS_Collection -Filter "Name='$collname'"

# create computer
$wmiconnection = ([WMIClass]"\\$serverhostname\root\SMS\Site_$sitecode:SMS_Site")
$newclient = $wmiconnection.psbase.GetMethodParameters("ImportMachineEntry")
$newclient.MACAddress = $mac
$newclient.NetbiosName = $clientname
$newclient.OverwriteExistingRecord = $true
$res = $wmiconnection.psbase.InvokeMethod("ImportMachineEntry",$newclient,$null)

# add client to collection
$newmembership = ([WMIClass]"\\$serverhostname\root\SMS\Site_$sitecode:SMS_CollectionRuleDirect").CreateInstance()
$newmembership.ResourceClassName = "SMS_R_SYSTEM"
$newmembership.ResourceID = $res.ResourceID
$newmembership.Rulename = $clientname

$collquery.AddMemberShipRule($newmembership)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.