Search code examples
powershellpowershell-2.0event-logpowershell-3.0powershell-remoting

Restarting PC's and writing to the event log with a custom message


I have written a script in PowerShell that will remotely restart a list of PC's using the 'Restart-Computer' command.

Is there a way of adding a custom message to the systems event log, to explain that the computer has been restart by my script.


Solution

  • Here is the PowerShell code that I used to solve this problem as suggested by the user C.B. above.

    Shutdown /r /f /m ComputerName /d P:0:1 /c "Your comment"

    This code will force (/f) a shut down and reboot (/r) of a given PC and write to the event log with a custom comment (/c). Note that to write a custom comment a reason code will need to be supplied using the (/d) parameter. Also note that the order of parameters matters.

    For a list of reason codes and syntax follow the links below.