Recommended Method to Process a List of Computers:
$computernames='web01','web02','web03'
restart-computer -computername $computernames -force -wait
Get-WmiObject win32_operatingsystem -computername $computernames | select-object @{LABEL='ComputerName';EXPRESSION={$_.csname}},@{LABEL='LastBootUpTime';EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}
# Sample Output:
ComputerName LastBootUpTime
------------ --------------
web01-APP01 11/6/2021 11:00:10 PM
web02-APP01 11/6/2021 10:20:50 PM
web03-APP01 11/6/2021 10:44:40 PM
Other Methods:
# Restart an array of computers
$computernames='web01','web02','web03'
restart-computer -computername $computernames -force -wait
Get-CimInstance -ClassName win32_OperatingSystem -ComputerName $computernames|select csname, lastbootuptime
# Pause after each machine is rebooted
$computers='web01','sql01'
$computers|%{
"rebooting $_ ? Ctrl+C to cancel..."
pause
restart-computer -computername $_ -force -wait
}
$computers|%{Get-CimInstance -ClassName win32_OperatingSystem -ComputerName $_ | select csname, lastbootuptime}
# Since Get-CimInstance relies on WinRM, this error sometimes would occur if WinRM is not setup properly at the remote nodes. Hence, Get-CimInstance is a more reliable method in those instances
Get-CimInstance : WinRM cannot process the request. The following error with errorcode 0x80090322 occurred while using
Kerberos authentication: An unknown security error occurred.
Possible causes are:
-The user name or password specified are invalid.
-Kerberos is used when no authentication method and no user name are specified.
-Kerberos accepts domain user names, but not local user names.
-The Service Principal Name (SPN) for the remote computer name and port does not exist.
-The client and remote computers are in different domains and there is no trust between the two domains.
After checking for the above issues, try the following:
-Check the Event Viewer for events related to authentication.
-Change the authentication method; add the destination computer to the WinRM TrustedHosts configuration setting or
use HTTPS transport.
Note that computers in the TrustedHosts list might not be authenticated.
-For more information about WinRM configuration, run the following command: winrm help config.
At line:1 char:1
+ Get-CimInstance -ClassName win32_OperatingSystem -ComputerName $compu ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : AuthenticationError: (root\cimv2:win32_OperatingSystem:String) [Get-CimInstance], CimExc
eption
+ FullyQualifiedErrorId : HRESULT 0x8033809d,Microsoft.Management.Infrastructure.CimCmdlets.GetCimInstanceCommand
+ PSComputerName : WEB02
Categories: