Trying to remotely restart a windows computer with powershell and Restart-Computer command.
Powershell is running from a docker container with mcr.microsoft.com/powershell image, and from within the docker container i am running a powerhell script.
The script is also tested on a windows 11 machine with powershell and it works as expected.
Output from the script running from powershell in docker, PowerShell 7.4.2.
PS />/root/scripts/restart.ps1
Restart-Computer: /root/scripts/restart.ps1:9
Line |
9 | Restart-Computer -ComputerName $server -Credential $credObject -Force …
| ~~~~~~~~~~~~~
| A parameter cannot be found that matches parameter name 'ComputerName'.
From the help it look likes there is a ComputerName parameter.
PS /> Get-Help Restart-Computer
NAME
Restart-Computer
SYNOPSIS
Restarts the operating system on local and remote computers.
SYNTAX
Restart-Computer [[-ComputerName*] <System.String[]>] [[-Credential] <System.Management.Automation.PSCredential>] [-Delay <System.Int16>] [-For {Wmi | WinRM | PowerShell}] [-Force] [-Timeout <System.Int32>] [-Wait] [-WsmanAuthentication {Basic*
| CredSSP | Default | Digest | Kerberos | Negotiate}] [-Confirm] [-WhatIf] [<CommonParameters>]
Obviously there is no parameter 'ComputerName' in the Restart-Computer command?
PS /> Get-Help * -Parameter ComputerName
Name Category Module Synopsis
---- -------- ------ --------
Enter-PSSession Cmdlet Microsoft.PowerShell.Core …
Get-PSSession Cmdlet Microsoft.PowerShell.Core …
Invoke-Command Cmdlet Microsoft.PowerShell.Core …
New-PSSession Cmdlet Microsoft.PowerShell.Core …
Receive-Job Cmdlet Microsoft.PowerShell.Core …
Remove-PSSession Cmdlet Microsoft.PowerShell.Core …
PS /> Get-Help * -Parameter ComputerName
Name Category Module Synopsis
---- -------- ------ --------
Enter-PSSession Cmdlet Microsoft.PowerShell.Core …
Get-PSSession Cmdlet Microsoft.PowerShell.Core …
Invoke-Command Cmdlet Microsoft.PowerShell.Core …
New-PSSession Cmdlet Microsoft.PowerShell.Core …
Receive-Job Cmdlet Microsoft.PowerShell.Core …
Remove-PSSession Cmdlet Microsoft.PowerShell.Core …
Regards Fredric Andersson
***moved from Windows / Other/Unknown / Other Windows apps***