通过Powershell安装SCCM包/应用程序



我制作了一个脚本,在任务序列之后的客户端部署周期中运行,其中安装了包和应用程序。然而,我们注意到它需要很长时间才能完成,因为大多数程序都处于evalutationState 26(下载成功(在安装作业期间下载))。我想强制安装程序,这些程序基本上处于这种状态,这样就不会花费很长时间来完成。

我已经看了一下关于安装ccm应用程序的MS文档(https://learn.microsoft.com/en-us/mem/configmgr/develop/reference/core/clients/sdk/install-method-in-class-ccm_application?redirectedfrom=MSDN),并做了如下:

$applications = get-wmiobject -query "SELECT * FROM CCM_Application" -namespace "ROOTccmClientSDK" | Select-Object FullName, InstallState, EvaluationState, ErrorCode, Id, Revision, IsMachineTarget
$appID = $applications.ID
$appRevision = $applications.Revision
$appMachineTarget = $applications.IsMachineTarget
try
{
# Documentation MS Docs - https://learn.microsoft.com/en-us/mem/configmgr/develop/reference/core/clients/sdk/install-method-in-class-ccm_application?redirectedfrom=MSDN
([WmiClass]'RootCCMClientSDK:CCM_Application').Install($appID, $appRevision, $appMachineTarget, 0, "Normal", $false) | Out-Null -ErrorAction Stop
}
catch [Exception]
{
$errorMessage = $_.Exception
Write-Log "Failed to start the installation. Reason: $errorMessage"
}

然而,当登录日志文件时,我可以看到我捕获了一个异常:


[17:04:31]:试图强制安装Citrix Netscaler Access Gateway 13.0.84.11 en-US

[17:04:31]: Failed to start the installation。原因:System.Runtime.InteropServices.COMException (0x80040E14)在System.Runtime.InteropServices.Marshal。ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)

在System.Management.ManagementObject。InvokeMethod(String methodName, ManagementBaseObject inParameters, InvokeMethodOptions options)

在System.Management.Automation.ManagementClassApdapter。调用管理方法(管理对象wmiObject,字符串方法名称,管理对象inParams)


我试着看看这篇文章(安装SCCM包与PowerShell),但答案:

Get-WmiObject -Class CCM_Program -Namespace "rootccmclientsdk"

不会显示与CCM_Application

相同的应用程序任何帮助都是感激的!提前感谢

我认为这个错误是由于预期的数据类型不匹配而发生的。我将把appID、appprevision、appMchineTarget的变量声明和方法调用移到foreach语句中,因为该方法在处理每个参数的数组时可能存在问题。

同样,CCM_Program不能显示应用程序,因为应用程序和程序是不同类型的"软件包"。在客户端,以及在服务器上。它们在WMI中分别处理。也许没有包部署到您的机器上?通过powershell管理软件包安装,你可以看看:https://learn.microsoft.com/de-de/mem/configmgr/develop/reference/core/clients/sdk/ccm_programsmanager-client-wmi-class

最新更新