PowerShell (Shutdown-Restart)

PowerShell is a platform that consists of a command line, a programming language, and a configuration manager. You can run it on Windows, Linux, and MacOS. With it, we can do the things that we do graphically in Windows with the command line. in this learning, we want to know, how we can use Shut down or Restart computer by command. let’s start PowerShell (Shutdown-Restart).

First, we open it from the Start menu.

This command will shut down computer as Force without any confirmation:

when we use this command, system will shut down without any confirmation, this command is useful when you want to shut down immediately, we dont have any option to set time, when we use -Force

  • Stop-Computer -Force
Syntax:
  • Stop-Computer [-WsmanAuthentication <String>] [[-ComputerName] <String[]>] [[-Credential] <PSCredential>] [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]
let’s to see video from our YouTube channel

This command shut down computer and ask for confirmation:

With this command we get a message to confirm shutdown, this command allows us to decide before shutdown. we can select to close all or select to close one by one.

  • Stop-Computer -Confirm

with option Yes ↓

Option Yes to All ↓

If you want to Restart your computer, you can directly use this command:

This command helps us to restart computers. in this action computer restart immediately and we dont have any option to delay.

  • Restart-Computer
Syntax:
  • Restart-Computer [-WsmanAuthentication <String>] [[-ComputerName] <String[]>] [[-Credential]<PSCredential>] [-Force] [-Wait] [-Timeout <Int32>] [-For <WaitForServiceTypes>] [-Delay <Int16>] [-WhatIf] [-Confirm] [<CommonParameters>]

If you want to Restart your computer with Delay, you can use these commands.

This is an effective way to choose restart computer with delay. In this action we have the option to select the time to Restart.

Note: In this tutorial, Time selected by Second

Syntax:
  • Start-Sleep [-Seconds] <Double> [<CommonParameters>]
  • Start-Sleep -seconds <Int32> [<CommonParameters>]
  • Start-Sleep -Duration <TimeSpan>[<CommonParameters>]

 

  • Start-Sleep -Seconds 5; Restart-Computer

If you want to see our learning about this topic, you can click here

 

Share :
198
keyboard_arrow_up