Retry application install in Configuration Manager client with powershell

Hey all, I've had not much luck finding complete examples on the internet that show how to initiate an application download and install on an SCCM client using powershell. I need to use this to create a script to clear the cache, re-download and install the application as it is failing on hundreds of computers.

I found this: https://msdn.microsoft.com/en-us/library/cc145211.aspx?f=255&MSPPError=-2147217396

But I don't know how to find the program or package Id. I found examples elsewhere on how it is acquired, but they seem to have access to wmi namespaces that don't exist on my clients.
LVL 2
byt3Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

byt3Author Commented:
Accidentally stumbled on the solution:

To clear the SCCM client cache

The SCCM client adds a Com service I can use:
$cm = New-Object -ComObject UIResource.UIResourceMgr
$cmcache = $cm.GetCacheInfo()
$cmcache.GetCacheElements() | Foreach-Object {
	$eid = $_.CacheElementId
	$cmcache.DeleteCacheElement($eid)
}

Open in new window


To have the SCCM client attempt installation of a deployed application:

The WMI class CCM_Application in the namespace Root\CCM\ClientSDK has an install method. This method takes 6 parameters - ApplicationId, Revision, IsMachineTarget, EnforcePreference, Priority, and IsRebootifNeeded . ApplicationId, Revision and IsMachineTarget  of the application to install can be retrieved by querying the CCM_Application class for the application.

Here's some example code searching for an application with office in the name
$app = Get-WmiObject -Namespace root\CCM\ClientSDK -Class CCM_Application | Where { $_.Name -like "*office*" }
$appid = $app.Id
$appRev = $app.Revision
$appTarget = $app.IsMachineTarget

Open in new window


The last 3 parameters have the following options:
EnforcePreference: 0 - Immediate, 1 - Non-Business hours or 2 - Admin Schedule
Priority: "Foreground", "High", "Normal" or "Low"
IsRebootIfNeeded: $true or $false

To gain access to the CCM_Application static method 'Install', I did it this way utilizing the variables I created above.
$ccm = [wmiclass]"Root\CCM\ClientSDK:CCM_Application"
$ccm.Install($appid,$appRev,$appTarget,0,"High",$false)

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Enterprise

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.