Restart server with comment

I want to restart a computer using powershell command.Does anyone know how to specify comments i.e (weekly restart) when restarting a server via PowerShell.

restart-computer a34x12 -force

There is no such thing for that cmdlet.
You create a scheduled task to fire off each week, then you assign your PS Script to that task.

When you want to know what a cmdlet / function does, that is what the help file is for.

# get function / cmdlet details
Get-Command -Name Restart-Computer -Syntax
(Get-Command -Name Restart-Computer).Parameters.Keys
(Get-Command Write-Host).Parameters.Object.ParameterSets.__AllParameterSets
Get-help -Name Restart-Computer -Full
Get-help -Name Restart-Computer -Online
Get-help -Name Restart-Computer -Examples

It’s in you script where you’ll place any other comments yo like, not that any one would see them, unless they opened the code in a editor to do so.

You can write your own help and then they could see notes that way, as with normal cmdlets / functions. See the docs on how to write comments or add help to your script.

not direct cmdlets as of now, but it can be done using Win32ShutdownTracker method of win32_operatingsystem class.

$OS = Get-CimInstance -Class Win32_OperatingSystem
$OS | Invoke-CimMethod -Name Win32ShutdownTracker -Arguments $TimeOut,$Comment,$ReasonCode,$Flag

See this documentation for supported values for $Flag,$Reason code.

Tagging to wot what kvprasoon is saying, (Win32ShutdownTracker - but I know many who disable this all the time as to not have to deal with it on shutdowns) you can easily use write to event log from your script prior to calling a shutdown command. Thus creating whatever audit / log message you choose.

How to Use PowerShell to Write to Event Logs