Kaseya Community

Running gpupdate /force

This question is answered

So I'm running into the same issue with running a gpupdate /force that has popped up in the forums already in some old unanswered threads.

I need to run a gpupdate /force on machines to push a GPO out.  I tried executeshellcommand("C:\windows\system32\gpupdate.exe /force", "Execute as User in 64-bit shell", "All Operating Systems", "Halt on fail") which didn't work and tried adding a second line of executeshellcommand("C:\windows\syswow64\gpupdate.exe /force", "Execute as User in 64-bit shell", "All Operating Systems", "Halt on fail") which didn't work either.

I'm actually getting an error in the procedure log 

Failed THEN in step 1 (Line 1)
FAILED in processing THEN step 1, Execute DOS Command, with error Spawn Failed, c:\windows\system32\gpupdate.exe /force (Line 1)

Thoughts?

Verified Answer
  • First I created a batch file

    gpupdate /force /target:computer

    gpupdate /force /target:user

    exit

    Saverd that to \vsasharedfiles.

    Then created the script as below.  Copy, save as XML then import.  That should work.

    <?xml version="1.0" encoding="utf-8"?>

    <ScriptExport xmlns:xsi="www.w3.org/.../XMLSchema-instance" xmlns:xsd="www.w3.org/.../XMLSchema" xmlns="www.kaseya.com/.../Scripting">

     <Procedure name="GPUpdate Force" treePres="3" id="2113793865" folderId="794520620067846" treeFullPath="myProcedures - Support.TEMP Files">

       <Body description="Deletes all files and folders within and below the logged on users %TEMP% folder that are not currently locked/open by Windows.">

         <If description="">

           <Condition name="TestFile">

             <Parameter xsi:type="StringParameter" name="Path" value="c:\temp\GPUpdate.bat" />

             <Parameter xsi:type="EnumParameter" name="Condition" value="Exists" />

             <Parameter xsi:type="StringParameter" name="Value" value="" />

           </Condition>

           <Then>

             <Statement name="ExecuteShellCommand" continueOnFail="false">

               <Parameter xsi:type="StringParameter" name="Command" value="cmd /C c:\temp\gpupdate.bat" />

               <Parameter xsi:type="EnumParameter" name="ExecuteAccount" value="System" />

               <Parameter xsi:type="BooleanParameter" name="Is64Bit" value="False" />

             </Statement>

           </Then>

           <Else>

             <Statement name="WriteFile" continueOnFail="false">

               <Parameter xsi:type="StringParameter" name="Path" value="c:\temp\gpupdate.bat" />

               <Parameter xsi:type="StringParameter" name="ManagedFile" value="VSASharedfiles\gpupdate.bat" />

               <Parameter xsi:type="BooleanParameter" name="DeleteAfter" value="False" />

             </Statement>

             <Statement name="ExecuteShellCommand" continueOnFail="false">

               <Parameter xsi:type="StringParameter" name="Command" value="c:\temp\gpupdate.bat >>>>c:\temp\gpupdate.txt" />

               <Parameter xsi:type="EnumParameter" name="ExecuteAccount" value="System" />

               <Parameter xsi:type="BooleanParameter" name="Is64Bit" value="False" />

             </Statement>

             <Statement name="DeleteFile" continueOnFail="false">

               <Parameter xsi:type="StringParameter" name="Path" value="c:\temp\gpupdate.bat" />

             </Statement>

           </Else>

         </If>

       </Body>

     </Procedure>

    </ScriptExport>

All Replies
  • First I created a batch file

    gpupdate /force /target:computer

    gpupdate /force /target:user

    exit

    Saverd that to \vsasharedfiles.

    Then created the script as below.  Copy, save as XML then import.  That should work.

    <?xml version="1.0" encoding="utf-8"?>

    <ScriptExport xmlns:xsi="www.w3.org/.../XMLSchema-instance" xmlns:xsd="www.w3.org/.../XMLSchema" xmlns="www.kaseya.com/.../Scripting">

     <Procedure name="GPUpdate Force" treePres="3" id="2113793865" folderId="794520620067846" treeFullPath="myProcedures - Support.TEMP Files">

       <Body description="Deletes all files and folders within and below the logged on users %TEMP% folder that are not currently locked/open by Windows.">

         <If description="">

           <Condition name="TestFile">

             <Parameter xsi:type="StringParameter" name="Path" value="c:\temp\GPUpdate.bat" />

             <Parameter xsi:type="EnumParameter" name="Condition" value="Exists" />

             <Parameter xsi:type="StringParameter" name="Value" value="" />

           </Condition>

           <Then>

             <Statement name="ExecuteShellCommand" continueOnFail="false">

               <Parameter xsi:type="StringParameter" name="Command" value="cmd /C c:\temp\gpupdate.bat" />

               <Parameter xsi:type="EnumParameter" name="ExecuteAccount" value="System" />

               <Parameter xsi:type="BooleanParameter" name="Is64Bit" value="False" />

             </Statement>

           </Then>

           <Else>

             <Statement name="WriteFile" continueOnFail="false">

               <Parameter xsi:type="StringParameter" name="Path" value="c:\temp\gpupdate.bat" />

               <Parameter xsi:type="StringParameter" name="ManagedFile" value="VSASharedfiles\gpupdate.bat" />

               <Parameter xsi:type="BooleanParameter" name="DeleteAfter" value="False" />

             </Statement>

             <Statement name="ExecuteShellCommand" continueOnFail="false">

               <Parameter xsi:type="StringParameter" name="Command" value="c:\temp\gpupdate.bat >>>>c:\temp\gpupdate.txt" />

               <Parameter xsi:type="EnumParameter" name="ExecuteAccount" value="System" />

               <Parameter xsi:type="BooleanParameter" name="Is64Bit" value="False" />

             </Statement>

             <Statement name="DeleteFile" continueOnFail="false">

               <Parameter xsi:type="StringParameter" name="Path" value="c:\temp\gpupdate.bat" />

             </Statement>

           </Else>

         </If>

       </Body>

     </Procedure>

    </ScriptExport>

  • Thank you that worked perfectly!