简体   繁体   English

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

[英]Install SCCM packages/Applications via Powershell

I've made a script that runs in our Client Deployment cycle after our task sequence, where packages and applications are being installed.我制作了一个脚本,在我们的任务序列之后在我们的客户端部署周期中运行,其中正在安装包和应用程序。 However, we noticed that it took a long time to finish, as most programs are in the evalutationState 26 (Download success (downloading during install job)).但是,我们注意到它需要很长时间才能完成,因为大多数程序都处于 evalutationState 26(下载成功(在安装作业期间下载))。 I want to force the installation of the programs, that essentially are in this state, so that it doesn't take ages to complete.我想强制安装程序,这些程序基本上都在这个 state 中,这样就不需要很长时间才能完成。

I've had a look MS Docs regarding installing ccm applications ( https://docs.microsoft.com/en-us/mem/configmgr/develop/reference/core/clients/sdk/install-method-in-class-ccm_application?redirectedfrom=MSDN ), and made the following:我查看了有关安装 ccm 应用程序的 MS Docs ( https://docs.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 "ROOT\ccm\ClientSDK" | Select-Object FullName, InstallState, EvaluationState, ErrorCode, Id, Revision, IsMachineTarget
$appID = $applications.ID
$appRevision = $applications.Revision
$appMachineTarget = $applications.IsMachineTarget
try
{
    # Documentation MS Docs - https://docs.microsoft.com/en-us/mem/configmgr/develop/reference/core/clients/sdk/install-method-in-class-ccm_application?redirectedfrom=MSDN
    ([WmiClass]'Root\CCM\ClientSDK: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"
}

However, when logging in the log file, I can see that I catch an exception:但是,在登录日志文件时,我可以看到我捕获了一个异常:


[17:04:31]: Trying to force installation of Citrix Netscaler Access Gateway 13.0.84.11 en-US [17:04:31]:尝试强制安装 Citrix Netscaler Access Gateway 13.0.84.11 en-US

[17:04:31]: Failed to start the installation. [17:04:31]:无法开始安装。 Reason: System.Runtime.InteropServices.COMException (0x80040E14) at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)原因:System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) 处的 System.Runtime.InteropServices.COMException (0x80040E14)

at System.Management.ManagementObject.InvokeMethod(String methodName, ManagementBaseObject inParameters, InvokeMethodOptions options)在 System.Management.ManagementObject.InvokeMethod(字符串方法名,ManagementBaseObject inParameters,InvokeMethodOptions 选项)

at System.Management.Automation.ManagementClassApdapter.InvokeManagementMethod(ManagementObject wmiObject, String methodName, ManagementBaseObject inParams)在 System.Management.Automation.ManagementClassApdapter.InvokeManagementMethod(ManagementObject wmiObject,String methodName,ManagementBaseObject inParams)


I tried having a look at this post ( Install SCCM packages with PowerShell ), but the answer:我试着看看这篇文章( 用 PowerShell 安装 SCCM 包),但答案是:

Get-WmiObject -Class CCM_Program -Namespace "root\ccm\clientsdk"

doesn't bring up the same applications as CCM_Application不会启动与 CCM_Application 相同的应用程序

Any help is appreciated!任何帮助表示赞赏! Thanks in advance提前致谢

I believe this error is happening due to an expected datatype mismatch.我相信这个错误是由于预期的数据类型不匹配而发生的。 I would move the variable declaration for appID,appRevision,appMchineTarget and the method-call into a foreach statement, since the method may have problems handling an array for every parameter.我会将 appID、appRevision、appMchineTarget 的变量声明和方法调用移动到 foreach 语句中,因为该方法在处理每个参数的数组时可能会遇到问题。

Also, the CCM_Program cannot display Applications, because Applications and Programs are different type of "softwarepackages" on the client, as well as on the server.此外,CCM_Program 不能显示应用程序,因为应用程序和程序是客户端和服务器上不同类型的“软件包”。 They are handled seperately in WMI.它们在 WMI 中单独处理。 Maybe there are no packages deployed to you machine?也许您的机器上没有部署任何软件包? For managing package-installation via powershell, you can take a look at: https://docs.microsoft.com/de-de/mem/configmgr/develop/reference/core/clients/sdk/ccm_programsmanager-client-wmi-class要通过 powershell 管理软件包安装,您可以查看: https ://docs.microsoft.com/de-de/mem/configmgr/develop/reference/core/clients/sdk/ccm_programsmanager-client-wmi-class

FYSA - Here is the same link pwe gave but in English: FYSA - 这是pwe提供的相同链接,但使用英文:
https://docs.microsoft.com/en-us/mem/configmgr/develop/reference/core/clients/sdk/ccm_programsmanager-client-wmi-class https://docs.microsoft.com/en-us/mem/configmgr/develop/reference/core/clients/sdk/ccm_programsmanager-client-wmi-class
(nothing against German, I just don't read it very well:-). (没有反对德语,我只是读得不太好:-)。

PS I don't have enough rep to post a comment on pwe's answer or that's where I would have put this. PS 我没有足够的代表来对 pwe 的答案发表评论,否则我就应该放这个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM