Initiate client policy retrieval by using script
Initiate client policy retrieval by using script – In this short post we will see how to Initiate client policy retrieval by using script. A Windows Configuration Manager client downloads its client policy on a schedule that you configure as a client setting. However, there might be occasions when you want to manually initiate policy retrieval from the client. For example, in a troubleshooting scenario when you have deployed a software to a collection or when you are testing. You could actually initiate client policy retrieval using the Actions tab on the Configuration Manager client but the script will also help you out. You must be logged onto the client computer with local administrative rights to perform these procedures.
The below script is taken from Technet. Copy the script into a notepad and save the file with filename.vbs extension.
on error resume next dim oCPAppletMgr 'Control Applet manager object. dim oClientAction 'Individual client action. dim oClientActions 'A collection of client actions. 'Get the Control Panel manager object. set oCPAppletMgr=CreateObject("CPApplet.CPAppletMgr") if err.number <> 0 then Wscript.echo "Couldn't create control panel application manager" WScript.Quit end if 'Get a collection of actions. set oClientActions=oCPAppletMgr.GetClientActions if err.number<>0 then wscript.echo "Couldn't get the client actions" set oCPAppletMgr=nothing WScript.Quit end if 'Display each client action name and perform it. For Each oClientAction In oClientActions if oClientAction.Name = "Request & Evaluate Machine Policy" then wscript.echo "Performing action " + oClientAction.Name oClientAction.PerformAction end if next set oClientActions=nothing set oCPAppletMgr=nothing
Initiate client policy retrieval by using script
To initiate client policy retrieval by using script, login to the client computer. Run the file using one of the following methods:
a) Navigate to the file by using Windows Explorer, and double-click the script file. Click OK in the Windows Script Host dialog box.
b) Open a command prompt, and type: cscript <pathfilename.vbs>.
VBS?? Why not PowerShell? Isn’t this the equivalent?
$CPAppletMgr = New-Object -ComObject CPApplet.CPAppletMgr
$ClientActions = $CPAppletMgr.GetClientActions()
ForEach ($ClientAction in $ClientActions) {
Write-Host “Performing action $($ClientAction.Name)”
$ClientAction.PerformAction | Out-Null
}
You could put a where or an if in there if you just want particular policies to run.
Yes you can run the powershell script as well. I just showed the example by running vbscript. I haven’t tested the powershell script yet, I will do it and if it works fine I will update the post or create a new one.
Thanks for the feedback 🙂