Shutdown :by using PowerShell UAC “Windows
administrators periodically” promotion press “start + R “ and write
“powershell
start-process powershell -verb runas”
Stop Computer SYNTAX
Stop-Computer [[-ComputerName]
<string[]>] [[-Credential] <pscredential>] [-AsJob]
[-DcomAuthentication {Default |
None | Connect | Call | Packet |
PacketIntegrity | PacketPrivacy | Unchanged}] [-WsmanAuthentication {Default |
Basic | Negotiate | CredSSP | Digest |
Kerberos}] [-Protocol {DCOM | WSMan}] [-Impersonation {Default | Anonymous
| Identify | Impersonate | Delegate}]
[-ThrottleLimit <int>] [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]
·
Computer Name: Target
Computer or specifies the computers to stop. The default is the local computer.
·
Credential: Type a user
name, such as User01 or Domain01\User01, or enter a PSCredential object, such as one from the Get-Credential
cmdlet.
·
AsJob: When you specify the
AsJob parameter, the command immediately returns an
object that represents the background job. You can continue to work in the
session while the job finishes. The job is created on the local computer and
the results from remote computers are automatically returned to the local
computer. To get the job results, use the Receive-Job cmdlet.
·
Confirm: Prompts you for
confirmation before running the cmdlet.
·
DcomAuthentication: uses
WMI. The acceptable values for this parameter are:
o
Default. Windows
Authentication
o
None. No COM authentication
o
Connect. Connect-level COM
authentication
o
Call. Call-level COM
authentication
o
Packet . Packet-level COM
authentication
o
PacketIntegrity. Packet
Integrity-level COM authentication
o
PacketPrivacy. Packet
Privacy-level COM authentication
o
Unchanged. Same as the
previous command
·
Force: Forces an immediate
shut down of the computers
·
Impersonation: Stop-Computer
uses WMI. The acceptable values for this parameter are:
o
Default. Default
impersonation.
o
Anonymous. Hides the
identity of the caller.
o
Identify. Allows objects to
query the credentials of the caller.
o
Impersonate. Allows objects
to use the credentials of the caller.
·
Protocol: Specifies which
protocol to use to restart the computers. The acceptable values for this
parameter are: WSMan and DCOM. The default value is DCOM. (PowerShell v3)
·
ThrottleLimit : Specifies
the maximum number of concurrent connections that can be established to run
this command. If you omit this parameter or enter a value of 0, the default
value, 32, is used.
·
WhatIf: Shows what would
happen if the cmdlet runs. The cmdlet is not run
Description
Example 1:
PS
C:\> Stop-Computer
This Command Stop local computer
Example 2:
PS C:\>
Stop-Computer -ComputerName
"Server01",
"Server02",
"localhost"
This command stops two remote computers,
Server01 and Server02, and the local computer, identified as localhost.
Example 3:
PS C:\>
Stop-Computer -ComputerName
"Server01" -Impersonation Anonymous
-Authentication PacketIntegrity
This command stops the Server01 remote computer. The
command uses customized impersonation and authentication settings.
Example 4:
PS C:\> Stop -computer (get-content c:\work\computers.txt)
-credential "mycompany\administrator"
You’ll get prompted for the password, but then this
credential will be used for every computer in the list.
This might fail if you have someone logged on to the
computer. In such cases you will receive below error.
PS C:\> Stop-Computer -ComputerName Server01
Stop-Computer : This command cannot be run on target computer(‘Server01) due to
following error: The system shutdown
cannot be initiated because there are other users logged on to the computer.
At line:1 char:1
+ Stop-Computer -ComputerName Server01
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Server01:String) [Stop-Computer],
InvalidOperationException
+ FullyQualifiedErrorId :
InvalidOperationException,Microsoft.PowerShell.Commands.StopComputerCommand
The solution in this is to use -Force switch to the above
command.
PS C:\>
Stop-Computer -ComputerName “Server01” –Force
Restart : by using PowerShell UAC “Windows
administrators periodically” promotion press “start + R “ and write
“powershell
start-process powershell -verb runas”
Restart Computer SYNTAX
restart-Computer [[-ComputerName]
<string[]>] [[-Credential] <pscredential>] [-AsJob]
[-DcomAuthentication {Default |
None | Connect | Call | Packet |
PacketIntegrity | PacketPrivacy | Unchanged}] [-WsmanAuthentication {Default |
Basic | Negotiate | CredSSP | Digest |
Kerberos}] [-Protocol {DCOM | WSMan}] [-Impersonation {Default | Anonymous
| Identify | Impersonate | Delegate}]
[-ThrottleLimit <int>] [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]
·
Computer Name: Target
Computer or specifies the computers to restart. The default is the local
computer.
·
Credential: Type a user
name, such as User01 or Domain01\User01, or enter a PSCredential object, such as one from the Get-Credential
cmdlet.
·
AsJob: When you specify the
AsJob parameter, the command immediately returns an
object that represents the background job. You can continue to work in the
session while the job finishes. The job is created on the local computer and
the results from remote computers are automatically returned to the local
computer. To get the job results, use the Receive-Job cmdlet.
·
Confirm: Prompts you for
confirmation before running the cmdlet.
·
DcomAuthentication: uses
WMI. The acceptable values for this parameter are:
o
Default. Windows
Authentication
o
None. No COM authentication
o
Connect. Connect-level COM
authentication
o
Call. Call-level COM
authentication
o
Packet. Packet-level COM
authentication
o
PacketIntegrity. Packet
Integrity-level COM authentication
o
PacketPrivacy. Packet
Privacy-level COM authentication
o
Unchanged. Same as the
previous command
·
Force: Forces an immediate
shut down of the computers
·
Impersonation: restart-Computer
uses WMI. The acceptable values for this parameter are:
o
Default. Default
impersonation.
o
Anonymous. Hides the
identity of the caller.
o
Identify. Allows objects to
query the credentials of the caller.
o
Impersonate. Allows objects
to use the credentials of the caller.
·
Protocol: Specifies which
protocol to use to restart the computers. The acceptable values for this
parameter are: WSMan and DCOM. The default value is DCOM. (PowerShell v3)
·
ThrottleLimit : Specifies
the maximum number of concurrent connections that can be established to run
this command. If you omit this parameter or enter a value of 0, the default
value, 32, is used.
·
WhatIf: Shows what would
happen if the cmdlet runs. The cmdlet is not run
Description
Example 1:
PS
C:\> restart-Computer
This Command restart local
computer
Example 2:
PS C:\>
restart-Computer -ComputerName
"Server01",
"Server02",
"localhost"
This command restarts two remote
computers, Server01 and Server02, and the local computer, identified as
localhost.
Example 3:
PS C:\>
restart-Computer -ComputerName
"Server01" -Impersonation Anonymous
-Authentication PacketIntegrity
This command restarts the Server01 remote computer. The
command uses customized impersonation and authentication settings.
Example 4:
PS C:\> restart-computer(get-content c:\work\computers.txt) -credential
"mycompany\administrator"
You’ll get prompted for the password, but then this
credential will be used for every computer in the list.
This might fail if you have someone logged on to the
computer. In such cases you will receive below error.
PS C:\> restart -Computer -ComputerName Server01
restart -Computer : This command cannot be run on target computer(‘Server01)
due to following error: The system shutdown
cannot be initiated because there are other users logged on to the computer.
At line:1 char:1
+ restart -Computer -ComputerName Server01
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Server01:String) [restart -Computer],
InvalidOperationException
+ FullyQualifiedErrorId :
InvalidOperationException,Microsoft.PowerShell.Commands. restartComputerCommand
The solution in this is to use -Force switch to the above
command.
PS C:\>
restart -Computer -ComputerName “Server01” –Force
0 comments :
Post a Comment