是否有可以启动另一台主机的powershell命令?

问题描述 投票:2回答:2

我有一组要关闭电源然后再打开的计算机,是否有Powershell命令可以执行此操作?我有“关机”命令将其关闭,我无法使用重新启动命令。

提前感谢!

powershell powershell-2.0 powershell-3.0 powershell-4.0 powershell-remoting
2个回答
2
投票

如果使用powershell 5.0 +,则可以使用Restart-Computer cmdlet。

$computers = @('name1','name2')

foreach ($computer in $computers)
{
    Restart-Computer -ComputerName $computer -Force
}

另一个替代方法是将shutdownCMD一起使用。

shutdown -i

将弹出一个不错的GUI来满足您的要求。enter image description here


1
投票

如果您愿意在PowerShell脚本中使用WMI,则Win32_OperatingSystem WMI类对象具有称为Win32ShutdownWin32Shutdown的方法,这两种方法都将允许您关闭或重新启动计算机,或者强制注销远程用户。我创建了一个scriptlet / script cmdlet /高级函数,该函数使用后者来完成您想要的工作;它适用于2.0上的任何版本的Windows PowerShell:

Win32ShutdownTracker
© www.soinside.com 2019 - 2024. All rights reserved.