Windows 7 Run ReRun SCCM SMS Advertisement to client

From richud.com
Jump to: navigation, search


Powershell

First you need a dump of available stuff and you must specify a username/password not rely on the normal 'impersonating' function.

psexec -u dom\username -p password \\host powershell.exe -Command "& {(New-Object -comobject UIResource.UIResourceMgr).GetAvailableApplications()}"

You need two things depending on what you are doing, viz 'PackageID', 'ProgID' (Listed as just 'Id') for each program.

In this example ,PackageID = UL10008D, ProgID = "MSI Install"

Check you have the right info with this that should just return one package. [with .GetProgram($ProgID, $PackageID)]

psexec -u dom\username -p password \\host powershell.exe -Command "& {(New-Object -comobject UIResource.UIResourceMgr).GetProgram('MSI Install', 'UL10008D')}"

You will get something dumped like this

Id                       : MSI Install
Name                     : MSI Install
Version                  :
AdditionalRequirements   :
DependentProgId          :
Enabled                  : 1
EstimatedDiskSpace       :
MaxRuntime               : 7200
CompletionAction         : 0
StartTime                : 13/03/2012 15:39:00
ExpiryTime               : 01/01/1970 00:00:00
RequiresUserInput        : 1
PackageId                : UL10008D
PackageName              : Acrobat X Pro
PackagePublisher         :
PackageLanguage          :
DependentPackageId       :
FullName                 : Acrobat X Pro - MSI Install
<SNIP>
IsOSDProgram             : 0
IsAssigned               : 1
BalloonRemindersRequired : 0
ContentSource            : 69

Some logged in on target

Now this only works without someone logged in to the remote target, which isn't so useful.

psexec -u dom\username -p password \\host powershell.exe -Command "& {(New-Object -comobject UIResource.UIResourceMgr).ExecuteProgram('MSI Install', 'UL10008D', 1)}"


No one logged in on target

This is far more useful as you can just run anything when the remote machine is switched on.

It also doesn't need psexec and doesn't need an further credential passing. (The account im running psexec from is in admin group on target, not sure if this matters)

This relies on the dll (smsclictr.automation.DLL) from SCCM Client Centre being available, in my case from 'C:\Program Files\SCCM Tools\SCCM Client Center\smsclictr.automation.DLL'

You also need to find the 'Advertisement ID' before you can use it. [function is .RerunAdv(AdvertisementID, PackageID, ProgramID ] (I cheated at this point and looked in SCCM Client centre for it, I am sure its easy enough to find though!!)

As a one liner;

powershell.exe -Command "& {Add-Type -Path 'C:\Program Files\SCCM Tools\SCCM Client Center\smsclictr.automation.DLL';(New-Object -TypeName smsclictr.automation.SMSClient('host')).SoftwareDistribution.RerunAdv('UL120034', 'UL10008D', 'MSI Install')}"


Broken down bit by bit;

Z:\>powershell
Windows PowerShell
Copyright (C) 2012 Microsoft Corporation. All rights reserved.

PS Z:\> Add-Type -Path 'C:\Program Files\SCCM Tools\SCCM Client Center\smsclictr.automation.DLL'
PS Z:\> $SMSClient = New-Object -TypeName smsclictr.automation.SMSClient("host")
PS Z:\> $SMSClient.SoftwareDistribution.RerunAdv("UL120034", "UL10008D", "MSI Install")
UL120034-UL10008D-B9A3E532

"UL120034-UL10008D-B9A3E532" is returned when its worked!

VB

You can do all the above with VB, I dislike VB though so this is just for info on how to trigger an install remotely...

A user MUST be logged in to the target PC for this to work, then run following via psexec passing credentials.

psexec -u dom\username -p password \\host cscript runadv.vbs

runadv.vbs

Set uiResource = CreateObject("UIResource.UIResourceMgr")
uiResource.ExecuteProgram "MSI Install", "UL10008D",True

You can also load the DLL as above with powershell and do the same, I didn't though as PS was good enough for me.

Comments

blog comments powered by Disqus