簡體   English   中英

PowerShell:如何在SCCM 2012中創建設備?

[英]PowerShell: How to create a device in SCCM 2012?

我需要使用PowerShell從正在運行的WinPE介質中創建SCCM對象/設備。 怎么會這樣呢?

我正在工作的公司的一名前雇員已經使用“ microsoft.configurationmanagement.managementprovider.dll”創建了一個C#Web解決方案,以創建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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM