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

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

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

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

例子

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

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

答案1

如果您感兴趣的话,这里有一个 vbscript 解决方案。我还不太熟悉 powershell,但我做了很多 .net 和 SCCM 的 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

相关内容