RE: Re-Run Advertisements



This is possible with a vbscript: you can run it from your local workstation.
Fill-in the name of the (remote) computer and de advertisementID. Works only
with per-system installations.

'Begin of script
on error resume Next

strMachine="<machinename>"
strAdvID="<AdvertisementID>"

' Get the ID of the ScheduledMessage on the target machine
strSchMsgID = GetAdvSchMsgID(strMachine, strAdvID)
If strSchMsgID = "" Then
MsgBox "Unable to get ScheduledMessageID. Program will not rerun.",
vbCritical OR vbOKOnly, "Rerun Advertisement Error"
WScript.Quit(-1)
Else
wscript.echo "Successfully retrieved schedule trigger " & strSchMsgID
End If


' Then make sure the program can be rerun
ret = SetRerunBehavior(strMachine, strAdvID, strOldRerunBehavior,
"RerunAlways")
If ret < 0 Then
MsgBox "Unable to set RerunBehaviour. Program will not rerun.",
vbCritical OR vbOKOnly, "Rerun Advertisement Error"
Wscript.Quit(ret)
Else
wscript.echo "Successfully set RerunBehaviour from " &
strOldRerunBehavior & " to RerunAlways."
End If

' Invoke SMS_Client.TriggerSchedule method
ret = TriggerSchedule(strMachine, strSchMsgID)
If ret < 0 Then
MsgBox "Unable to trigger advertisement. Program will not rerun.",
vbCritical OR vbOKOnly, "Rerun Advertisement Error"
Wscript.Quit(ret)
Else
wscript.echo "Successfully triggered schedule."
end If

' give the client some time to create the execution request
wscript.sleep 5000

'Reset the ADV_RepeatRunBehavior state to the previous value
ret = SetRerunBehavior(strMachine, strAdvID, strDummy, strOldRerunBehavior)
If ret < 0 Then
MsgBox "Unable to reset RerunBehaviour. Please refresh policy manually
or wait a few minutes!", vbExclamation OR vbOKOnly, "Rerun Advertisement
Warning"
Wscript.Quit(ret)
Else
wscript.echo "Successfully set RerunBehaviour from RerunAlways to " &
strOldRerunBehavior & "."
end If

MsgBox "Successfully triggered rerunning!", vbInformation OR vbOKOnly,
"Rerun Advertisement"



Function GetAdvSchMsgID(strMachine, strAdvID)
err.clear
GetAdvSchMsgID=""

' Connect to the actual configuration policy via WMI
set objNMS = GetObject("winmgmts://" & strMachine &
"/root/ccm/policy/machine/actualconfig")
if (Err.number <> 0) Then
wscript.echo "Failed to connect to actual config on " & strMachine &
": " & Err.Description & " (" & Err.number & ")"
Exit Function
end If

' find the matching ScheduledMessage
' Cannot use like operator on machines lower than XP/W2K3, so must first
get all
Set objScheds = objNMS.ExecQuery("select * from
CCM_Scheduler_ScheduledMessage")
if (Err.number <> 0) Then
wscript.echo "Failed to query schedules on " & strMachine & ": " &
Err.Description & " (" & Err.number & ")"
Exit Function
end If

' Search for match by string comparison
For each objSched in objScheds
If Instr(objSched.ScheduledMessageID, strAdvID) > 0 then
GetAdvSchMsgID = objSched.ScheduledMessageID
Exit For
End If
Next

if GetAdvSchMsgID = "" then
wscript.echo "Unable to identify the trigger ID. Program will not
rerun."
end if

End Function

function SetRerunBehavior(strMachine, strAdvID, strOldRerunBehavior,
strRerunBehavior)
set objNMS = GetObject("winmgmts://" & strMachine &
"/root/ccm/policy/machine/actualconfig")
if (Err.number <> 0) then
wscript.echo "Failed to connect to actual config on " & strMachine &
": " & Err.Description & " (" & Err.number & ")"
SetRerunBehavior = -1
Exit Function
end if

' wscript.echo "Executing query select * from CCM_SoftwareDistribution
where ADV_AdvertisementID = '" & strAdvID & "'"

Set objScheds = objNMS.ExecQuery("select * from CCM_SoftwareDistribution
where ADV_AdvertisementID = '" & strAdvID & "'" )
if (Err.number <> 0) then
wscript.echo "Failed to query advertisements on " & strMachine & ": "
& Err.Description & " (" & Err.number & ")"
SetRerunBehavior = -2
exit Function
end if

' there is only one item in the collection
if (objScheds.Count <> 1) then
wscript.echo "Unable to identify advertisement. Program will not
rerun. Count = " & objScheds.Count
SetRerunBehavior = -3
' exit Function
end If

for each objSched in objScheds
strOldRerunBehavior = objSched.ADV_RepeatRunBehavior
objSched.ADV_RepeatRunBehavior = strRerunBehavior
objSched.Put_ 0
if (Err.number <> 0) then
wscript.echo "Failed to set ADV_RerunBehavior for advertisement "
& strAdvID & " on " & strMachine & ": " & Err.Description & " (" & Err.number
& ")"
SetRerunBehavior = -4
exit function
end if
Next
SetRerunBehavior = 0
wscript.echo "Successfully set set ADV_RerunBehavior for advertisement "
& strAdvID & " on " & strMachine & " from " & strOldRerunBehavior & " to " &
strRerunBehavior
end Function


Function TriggerSchedule(strMachine, strSchMsgID)

set objNMS = GetObject("winmgmts://" & strMachine & "/root/ccm")
if (Err.number <> 0) then
wscript.echo "Failed to connect to WMI on " & strMachine & ": " &
Err.Description & " (" & Err.number & ")"
TriggerSchedule = -1
Exit Function
end if

'wscript.echo "Successfully connected to WMI"

dim objSMSClient
Set objSMSClient = objNMS.Get("SMS_Client")
if (Err.number <> 0) then
wscript.echo "Failed to get the SMS_Client class " & Err.Description
& " (" & Err.number & ")"
TriggerSchedule = -2
Exit Function
end if

objSMSClient.TriggerSchedule strSchMsgID
if (Err.number <> 0) then
wscript.echo "Method failed: " & Err.Description & " (" & Err.number
& ")"
TriggerSchedule = -3
Exit Function
end if
TriggerSchedule = 0
End Function

'End of script
--
Michiel Wouters [MCSE 2003]

Before you post, think about the brain you host ;)


"Tim" wrote:

How can I Re-send advertisements to a single computer that's in a collection
that has been sent the advertisement already.
If i re-run advertisements it resends to all computers in collection.
I just need to resend to one computer in collection.


thanks,

Tim
.



Relevant Pages

  • Re: Re-Run Mandatory job - Advanced Client
    ... schedule, since ... >will not rerun. ... >generate a new program id)and a new advertisement. ... On the advanced client, delete the ...
    (microsoft.public.sms.admin)
  • Re: Re-running OS deployment to one computer in a collection?
    ... you've installed "SMS Tools" ... delete the PackageID entry you want the client to rerun. ... An Advertisement has been created that installs an OS on the computers ...
    (microsoft.public.sms.admin)
  • RE: Recurring Advertisements fail to rerun
    ... advertisement to rerun, otherwise the FailureNoRetry flag will exclude the ... I always get machines that would fail randomly, ... if I try to rerun the advertisement ... manually using the SMS Tools that I downloaded from the internet - a tool ...
    (microsoft.public.sms.admin)
  • RE: SMS 2003 Query Software Distribution Status
    ... actually corresponds to my point 1 in rerunning. ... Being an advertisement that has multiple schedules. ... rerun on all systems, failed & successful alike. ... clients that failed once would then rerun the ...
    (microsoft.public.sms.admin)