Powershell
通過 powershell、命令行或 WMI 將 SCCM 應用程序安裝到客戶端
我正在嘗試在 powershell 中創建一個腳本,該腳本請求並為 sccm 應用程序目錄中的使用者或電腦安裝可用的應用程序。
我知道有一種方法可以使用 wmi 方法強制 sccm 客戶端操作。
例子
WMIC /namespace:\\root\ccm path sms_client CALL TriggerSchedule "{00000000-0000-0000-0000-000000000003}" /NOINTERACTIVE
有一種方法可以通過在使用者電腦中執行 wmi 方法或命令行來強制安裝應用程序。
如果您有興趣,這是 vbscript 中的解決方案。我還不精通powershell,但我做了很多SCCM的.net和vbscript自動化。我敢肯定這裡有人可以翻譯成powershell。
'Declare WMI connection to CCM, temporarily disable errors so the script doesnt stop if the namespace doesn't exist. We will handle the error next. On Error Resume Next Dim oWMI : Set oWMI = GetObject("winmgmts:\\.\root\ccm\ClientSDK") On Error Goto 0 ' Check the datatype of oWMI to make sure its not null for error handling. If VarType(oWMI) > 1 Then 'Run a query for all applications Dim colItems, objItem : Set colItems = oWMI.ExecQuery("Select * from CCM_Application") 'Same as above... error handling in case nothing was returned If VarType(colItems) > 1 Then ' Iterate through all the applications available For Each objItem in colItems Wscript.Echo "Application: " & objItem.FullName & vbCr & _ "Description: " & objItem.Description & VbCr & _ "Publisher: " & objItem.Publisher & VbCr & _ "Version: " & objItem.SoftwareVersion & VbCr & _ "Install State: " & objItem.InstallState & VbCr & _ "Id: " & objItem.Id & VbCr & _ "Revision: " & objItem.Revision 'In my example, if the application is Adobe Air then run the install action If objItem.FullName = "Adobe Air" and ObjItem.InstallState = "NotInstalled" Then 'First three parameters identify the application (id, revision, and ismachinetarget). The Next 3 are EnforcePreference, Priority and IsRebootIfNeeded options. '0, "Foreground", "False" sets immediate foreground install with no reboot 'See the msdn page for info about what other options you can set: https://msdn.microsoft.com/library/jj902780.aspx Dim ReturnCode : ReturnCode = objItem.Install(objItem.Id, objItem.Revision, objItem.IsMachineTarget, 0, "Foreground", "False") 'Returns 0 if it successfully started the install. This does NOT return the exit code of the installation itself. Wscript.Echo "Return Code: " & ReturnCode End If Next End If End If