Stop-Computer
停止(关闭)本地和远程计算机。
语法
Stop-Computer
[-WsmanAuthentication <String>]
[[-ComputerName] <String[]>]
[[-Credential] <PSCredential>]
[-Force]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
说明
Stop-Computer
cmdlet 关闭本地计算机和远程计算机。
可以使用 Stop-Computer
的参数来指定身份验证级别和备用凭据,并强制立即关闭。
在 PowerShell 7.1 中,为 Linux 和 macOS 添加了 Stop-Computer
。 这些参数对这些平台没有影响。 cmdlet 只是调用本机命令 /sbin/shutdown
。
示例
示例 1:关闭本地计算机
此示例关闭本地计算机。
Stop-Computer -ComputerName localhost
示例 2:关闭两台远程计算机和本地计算机
此示例停止两台远程计算机和本地计算机。
Stop-Computer -ComputerName "Server01", "Server02", "localhost"
Stop-Computer
使用 ComputerName 参数指定两台远程计算机和本地计算机。 每台计算机都已关闭。
示例 3:将远程计算机作为后台作业关闭
在此示例中,Stop-Computer
作为后台作业在两台远程计算机上运行。
后台运算符 &
以后台作业的形式运行 Stop-Computer
命令。 有关详细信息,请参阅 about_Operators。
$j = Stop-Computer -ComputerName "Server01", "Server02" &
$results = $j | Receive-Job
$results
Stop-Computer
使用 ComputerName 参数指定两台远程计算机。
&
后台运算符将命令作为后台作业运行。 作业对象存储在 $j
变量中。
$j
变量中的作业对象将向下发送到 Receive-Job
,从而获取作业结果。 对象存储在 $results
变量中。
$results
变量在 PowerShell 控制台中显示作业信息。
示例 4:关闭远程计算机
此示例使用指定的身份验证关闭远程计算机。
Stop-Computer -ComputerName "Server01" -WsmanAuthentication Kerberos
Stop-Computer
使用 ComputerName 参数指定远程计算机。
WsmanAuthentication 参数指定使用 Kerberos 建立远程连接。
示例 5:关闭域中的计算机
在此示例中,命令强制立即关闭指定域中的所有计算机。
$s = Get-Content -Path ./Domain01.txt
$c = Get-Credential -Credential Domain01\Admin01
Stop-Computer -ComputerName $s -Force -Credential $c
Get-Content
使用 Path 参数获取包含域计算机列表的当前目录中的文件。 对象存储在 $s
变量中。
Get-Credential
使用 Credential 参数指定域管理员的凭据。 凭据存储在 $c
变量中。
Stop-Computer
关闭使用 ComputerName 参数 $s
变量中的计算机列表指定的计算机。
Force 参数强制立即关闭。
Credential 参数提交保存在 $c
变量中的凭据。
参数
-ComputerName
指定要停止的计算机。 默认值为本地计算机。
在逗号分隔的列表中,键入一个或多个计算机的 NETBIOS 名称、IP 地址或完全限定的域名。 若要指定本地计算机,请键入计算机名称或 localhost。
此参数不依赖于 PowerShell 远程处理。 即使计算机未配置为运行远程命令,也可以使用 ComputerName 参数。
类型: | String[] |
别名: | CN, __SERVER, Server, IPAddress |
Position: | 0 |
默认值: | None |
必需: | False |
接受管道输入: | True |
接受通配符: | False |
-Confirm
在运行 cmdlet 之前,提示你进行确认。
类型: | SwitchParameter |
别名: | cf |
Position: | Named |
默认值: | False |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-Credential
指定有权执行此作的用户帐户。 默认值为当前用户。
键入用户名(如 User01 或 Domain01\User01),或输入由 Get-Credential
cmdlet 生成的 PSCredential 对象。 如果键入用户名,系统会提示输入密码。
凭据存储在 PSCredential 对象中,密码存储为 SecureString。
注意
有关 SecureString 数据保护的详细信息,请参阅 SecureString 的安全性如何?。
类型: | PSCredential |
Position: | 1 |
默认值: | Current user |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-Force
强制立即关闭计算机。
类型: | SwitchParameter |
Position: | Named |
默认值: | False |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-WhatIf
显示 cmdlet 运行时会发生什么情况。 该 cmdlet 未运行。
类型: | SwitchParameter |
别名: | wi |
Position: | Named |
默认值: | False |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-WsmanAuthentication
指定此 cmdlet 使用 WSMan 协议时用于对用户凭据进行身份验证的机制。 默认值 默认值。
此参数的可接受值为:
- 基本
- CredSSP
- 违约
- 消化
- Kerberos
- 谈判。
有关此参数的值的详细信息,请参阅 AuthenticationMechanism。
谨慎
凭据安全服务提供程序(CredSSP)身份验证(其中用户凭据传递到要进行身份验证的远程计算机)旨在用于需要对多个资源进行身份验证的命令,例如访问远程网络共享。 此机制会增加远程作的安全风险。 如果远程计算机遭到入侵,则传递给它的凭据可用于控制网络会话。
此参数是在 PowerShell 3.0 中引入的。
类型: | String |
接受的值: | Default, Basic, Negotiate, CredSSP, Digest, Kerberos |
Position: | Named |
默认值: | Default |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
输入
None
不能通过管道将对象传递给此 cmdlet。
输出
None
此 cmdlet 不返回任何输出。
备注
此 cmdlet 使用
Win32_OperatingSystem
WMI 类的 Win32Shutdown
方法。 此方法要求为用于关闭计算机的用户帐户启用 SeShutdownPrivilege
特权。
在 PowerShell 7.1 中,为 Linux 和 macOS 添加了 Stop-Computer
。 对于这些平台,cmdlet 调用本机命令 /sbin/shutdown
。