powershell - 重新启动PC并使用自定义消息写入事件日志

标签 powershell powershell-2.0 event-log powershell-3.0 powershell-remoting

我在PowerShell中编写了一个脚本,该脚本将使用“重新启动计算机”命令远程重新启动PC列表。

有没有一种方法可以向系统事件日志中添加自定义消息,以说明我的脚本已重新启动计算机。

最佳答案

这是上面用户C.B.建议用来解决此问题的PowerShell代码。
Shutdown /r /f /m ComputerName /d P:0:1 /c "Your comment"
此代码将强制(/ f)关闭并重新引导给定PC,并使用自定义注释(/ c)写入事件日志。 请注意,要编写自定义注释,将需要使用(/ d)参数提供原因代码。还要注意,参数的顺序很重要。

有关原因代码和语法的列表,请单击下面的链接。

  • http://ss64.com/nt/shutdown.html
  • http://technet.microsoft.com/en-us/library/cc732503(v=ws.10).aspx
  • 关于powershell - 重新启动PC并使用自定义消息写入事件日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15656106/

    相关文章:

    delphi - TEventLogger 有灯吗?

    azure - 使用 PowerShell 更改 Azure VM 的密码

    iis - 将 IIS 应用程序池回收事件记录在 Windows 事件日志中

    Powershell 函数限制数据类型

    powershell - CSV文件按col1分组并显示col2的最大值

    powershell - 在 Powershell 中,在单个脚本文件中编写多个函数是一种好习惯吗?

    powershell - 使用参数不在脚本文件中的Powershell

    logging - Powershell 计划任务冲突?

    sql-server - 防止单引号破坏sql命令

    c# - 在 C# 中将 PSObjects(或 PS 命令)转换为 JSON