我需要使用 PowerShell 从正在运行的 WinPE 介质创建 SCCM 对象/设备。怎么会有这样的事情?
我工作的公司的一位前雇员创建了一个 C# Web 解决方案,使用“microsoft.configurationmanagement.managementprovider.dll”来创建 SCCM 设备并为其添加属性。我必须将此函数迁移到在 WinPE 上运行的 PowerShell 脚本。
任何输入,关于这个的指针?提前致谢
我需要使用 PowerShell 从正在运行的 WinPE 介质创建 SCCM 对象/设备。怎么会有这样的事情?
我工作的公司的一位前雇员创建了一个 C# Web 解决方案,使用“microsoft.configurationmanagement.managementprovider.dll”来创建 SCCM 设备并为其添加属性。我必须将此函数迁移到在 WinPE 上运行的 PowerShell 脚本。
任何输入,关于这个的指针?提前致谢
也许你可以这样:
# 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)