I need two scripts one that will do GPUpdate /force then reboot PC

and one that does

GPUdate /force without reboot.

2 Comments   [ + ] Show Comments

Comments

  • 'Define Variables and Objects.
    Set WshShell = CreateObject("Wscript.Shell")

    'Note: Gpupdate command has to be run twice as the ECHO command can't answer more than one question.

    'Refresh the USER policies and also answer no to logoff if asked.
    'Result = WshShell.Run("cmd /c echo n | gpupdate /target:user /force",0,true)

    'Refresh the Computer policies and answer no to reboot.
    Result = WshShell.Run("cmd /c echo n | gpupdate /target:computer /force",0,true)

    'Hand back the errorlevel
    Wscript.Quit(Result)
  • Are you looking to use Kace scripting?
Please log in to comment

Community Chosen Answer

2
Ok gpupdate basics then on to your script. 

You are doing the user separately, no need to run 2 commands.

Be aware that doing a /force on a lot of machines at the same time can cause problems with your DC's and the network.

It needs to be an online script for the user to update

here is the easy way to do gpupdate via KScript on v3.7
lA9peI.jpeg
Here is with a force
deE0UL.jpeg
Then add either the /logoff switch if only user policies have changed or the /boot switch for both policies.


GTVTDP.jpeg

YX0ZWs.jpeg

Description:  Updates Group Policies settings.



Syntax: GPUpdate [/Target:{Computer | User}] [/Force] [/Wait:<value>]

[/Logoff] [/Boot] [/Sync]



Parameters:



Value Description

/Target:{Computer | User} Specifies that only User or only Computer

policy settings are updated. By default,

both User and Computer policy settings are

updated.



/Force Reapplies all policy settings. By default,

only policy settings that have changed are

applied.



/Wait:{value} Sets the number of seconds to wait for policy

processing to finish. The default is 600

seconds. The value '0' means not to wait.

The value '-1' means to wait indefinitely.

When the time limit is exceeded, the command

prompt returns, but policy processing

continues.



/Logoff Causes a logoff after the Group Policy settings

have been updated. This is required for

those Group Policy client-side extensions

that do not process policy on a background

update cycle but do process policy when a

user logs on. Examples include user-targeted

Software Installation and Folder Redirection.

This option has no effect if there are no

extensions called that require a logoff.



/Boot Causes a computer restart after the Group Policy settings

are applied. This is required for those

Group Policy client-side extensions that do

not process policy on a background update cycle

but do process policy at computer startup.

Examples include computer-targeted Software

Installation. This option has no effect if

there are no extensions called that require

a restart.



/Sync Causes the next foreground policy application to

be done synchronously. Foreground policy

applications occur at computer boot and user

logon. You can specify this for the user,

computer or both using the /Target parameter.

The /Force and /Wait parameters will be ignored

if specified.




Answered 05/22/2015 by: SMal.tmcc
Red Belt

Please log in to comment

Answers

0

I found this and it works for no logoff. But I want it to exit cmd prompt. Cmd prompt is still open and up. user will have to exit cmd prompt and I don't want user to do anything.

'====================
 Set objFSO = CreateObject("Scripting.FileSystemObject")
 Set objShell = CreateObject("WScript.Shell")
 strInputFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "input.txt"

 Set objInputFile = objFSO.CreateTextFile(strInputFile, True)
 objInputFile.WriteLine "n"
 objInputFile.WriteLine "n"
 objInputFile.Close
 Set objInputFile = Nothing

 strInputFile = objFSO.GetFile(strInputFile).ShortPath

 ' FOR TESTING, USE /k and 1, AFTER TESTING, USE /c and 0
 strCommand = "cmd /k gpupdate /force < " & strInputFile
 objShell.Run strCommand, 1, True

 objFSO.DeleteFile strInputFile, True
 Set objFSO = Nothing
 Set objShell = Nothing

 ' The line below can be commented out when you have finished testing to keep it silent.
 MsgBox "Script finished."
 '====================

Answered 05/22/2015 by: Kdebiasse
Sixth Degree Black Belt

  • Hi there,
    Is this a BAT or VBS script.
    How do i run it if i had to, as a post install task in the k2000 ?
    Thanks.
Please log in to comment
0
Got it to work. Thank everyone that answered the question.,
Answered 05/22/2015 by: Kdebiasse
Sixth Degree Black Belt

Please log in to comment
0
Got it to work. Thank everyone that answered the question.,
Answered 05/22/2015 by: Kdebiasse
Sixth Degree Black Belt

Please log in to comment
Answer this question or Comment on this question for clarity
Admin Script Editor
Admin Script Editor is an integrated scripting environment available free here at ITNinja

Share