通过服务器上的 Powershell 在 SCCM 中执行安装命令

Execute install command in SCCM via Powershell on servers

我想通过 powershell 在服务器上安装特定的包。

Get-WmiObject -Namespace  ROOT\ccm\ClientSDK -Class CCM_Application -ComputerName Y31056 | Select-Object AllowedActions, Fullname

而且我可以列出服务器上安装或未安装的软件。 所以我只想在软件中心安装特定的包。

AllowedActions                                                             Fullname                                                                  
--------------                                                             --------                                                                  
{Install}                                                                  CMTrace                                                                   
{Install}                                                                  SCCMpackageV1                                          
{Install}                                                                  SQL Server 2014 SP2     

我想要 运行 通过 powershell 安装 SCCMpackageV1 的脚本,但对如何实现它有点困惑。

$SoftwareApp = Get-WmiObject -Namespace  ROOT\ccm\ClientSDK -Class CCM_Application -ComputerName Y31056 | Select-Object AllowedActions, Fullname
$SoftwareApp.install.SCCMpackageV1

我 google 简单的安装命令应该可以工作,但我没有收到任何输出。软件也没有安装。

CCM_Application 对象的 Install 方法需要提供参数。微软官方文档对每个参数都有非常详细的说明,你可以参考下面link: https://msdn.microsoft.com/en-us/library/jj902785.aspx

以下面的代码为例,在客户端机器上安装应用程序:

$ComputerName = "Y31056"
$AppName = "SCCMPackageV1"

$s = New-PSSession -ComputerName $ComputerName
Invoke-Command -Session $s -Argu $ComputerName,$AppName -ScriptBlock `
{
param ($ComputerName,$AppName)
write-host "Getting Parameters for '$AppName' on $ComputerName"
$Application = Get-WmiObject -computername $ComputerName -Namespace "root\ccm\ClientSDK" -Class CCM_Application | where {$_.Name -like "$AppName"} | Select-Object Id, Revision, IsMachineTarget
$AppID = $Application.Id
$AppRev = $Application.Revision
$AppTarget = $Application.IsMachineTarget
([wmiclass]'ROOT\ccm\ClientSdk:CCM_Application').Install($AppID, $AppRev, $AppTarget, 0, 'Normal', $False) | Out-Null
}
Remove-PSSession $s