I am trying to remotely force a GPUpdate by means of invoke-command as Invoke-GPUpdate is not available to me in my environment. I was messing around with it one day and it executed as expected, but since then I have been unable to get it to work. It may be environment related, but I just wanted to double check what I have is correct, or there are alternatives I am unaware of. I am currently just trying to call CMD for it to run "Gpupdate /force" but it just hangs on a blank line after execution.
Doing
& cmd.exe /c "msg * hi"
as expected brings up a popup saying hi.
I have tried pretty much every permutation of the below:
& cmd.exe /c 'gpupdate /force'
cmd.exe /c 'gpupdate /force'
cmd.exe 'gpupdate /force'
cmd 'gpupdate /force'
& cmd 'gpupdate /force'
Eventually I would like it to be something like this
Invoke-Command -computername $Computer -Credentials $Cred -Scriptblock{& cmd.exe /c 'gpupdate /force'}
Am I doing something wrong with the Syntax?
@Minkulai pointed out the obvious, but I didn't want to leave this unanswered. This is what I ended up using:
Invoke-Command -ComputerName $Computer -ScriptBlock {GPUpdate /Force}
I am running this cmdlet from an elevated script already so the -Credentials $Cred
portion in @Minkulai's comment is not necessary, but may be needed if your script does not have rights to run.