首页 > 解决方案 > Powershell Invoke-GPUpdate - “没有注销”可能吗?

问题描述

希望运行Invoke-GPUPdate -force到一组远程计算机并以“否”响应注销提示。

试过:

Echo "n" | invoke-gpupdate

错误:Invoke-gpupdate 不接受管道输入

使用的命令:

Invoke-GPUpdate -Computer $computer -RandomDelayInMinutes 0 -force

对 GPUpdate 的注销响应图片

标签: powershell

解决方案


不幸的是,看起来这个 cmdlet 启动/安排了一次 gpupdate 运行,该运行最终单独发生(进程外),因此通过 PowerShell 处理此类事情的标准方法没有太多可做的,因为提示没有出现从 PowerShell 中。有一个-LogOff参数,但它是一个开关参数,这意味着它的值仅用于注销。您可以这样尝试:-Logoff:$false但很可能无法摆脱提示。

我认为您最好的机会不是使用此 cmdlet,而是直接使用Invoke-Commandwith gpupdate.exe

Invoke-Command -ComputerName $computer -ScriptBlock {
    echo nn | gpupdate.exe /force
}

但这需要在您要管理的计算机上启用 PowerShell 远程处理。


推荐阅读