通过PowerShell,命令行或WMI将SCCM应用程序安装到客户端

我正在尝试在PowerShell中创build一个脚本,请求并为sccm应用程序目录中的用户或计算机安装可用的应用程序。

我知道有一种方法可以使用wmi方法强制sccm客户端操作。

WMIC /namespace:\\root\ccm path sms_client CALL TriggerSchedule "{00000000-0000-0000-0000-000000000003}" /NOINTERACTIVE 

有一种方法是通过在用户计算机上执行wmi方法或命令行来强制安装和应用程序。

如果你有兴趣,这是一个在VBScript的解决scheme。 我不熟悉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