-->

Install SCCM packages with PowerShell

2019-08-17 03:35发布

问题:

I have this script so I can install applications that are available in SCCM with Powershell.

I'm trying to do it with a package, but can not make it work. Is there anybody who can help make the script so it works for packages. Thanks

$ComputerName = $env:COMPUTERNAME
$ApplicationName = "VLC Player"
$ApplicationClass = [WmiClass]"\\$($ComputerName)\root\ccm\clientSDK:CCM_Application"
$Application = Get-WmiObject -Namespace "root\ccm\clientSDK" -Class CCM_Program | Where-Object { $_.Name -like "*$($ApplicationName)*" }
$ApplicationID = $Application.Id
$ApplicationRevision = $Application.Revision
$ApplicationClass.Install($ApplicationID,$ApplicationRevision,$false,0,"High",$false)

回答1:

I never tried it but according to my research it should be done with the ExecutePrograms class of CCM_ProgramsManager

So it would look something like:

$i = Get-WmiObject -Class CCM_Program -Namespace "root\ccm\clientsdk" | Where-Object { $_.Name -like "*some search term*" }    
Invoke-WmiMethod -class CCM_ProgramsManager -Namespace "root\ccm\clientsdk" -Name ExecutePrograms  -argumentlist $i

What I find interesting is that the examples I found all use ExecutePrograms and not the ExecuteProgram method that exists as well. Maybe this comes from the fact how the Get-WmiObject always returns a list even if it has only one item, but I don't know.

Also just a general reminder: In general there is a reason why a software is available and that is that it should not be installed automatically. If you want it installed automatically you should set it to required and let the sccm handle the install.