powershell - 使用 powershell 脚本重启机器
问题描述
我正在运行以下代码,但重新启动不起作用。我的意图是一次在所有远程机器上并行运行重启命令。
$YourFile = gc "machinelst.txt"
$username = "user1"
$password = "pass1"
$secpw = ConvertTo-SecureString $password -AsPlainText -Force
$cred = New-Object Management.Automation.PSCredential ($username, $secpw)
foreach ($computer in $YourFile)
{
Invoke-Command -ComputerName $computer -credential $cred -ErrorAction Stop -ScriptBlock { Restart-Computer -ComputerName $computer -Force } -AsJob
}
解决方案
这看起来像是 Get-Job 的输出 - 你可以试试 Receive-Job $id (Receive-Job 80)。
应该给你实际的例外。
推荐阅读
- git - 使用 git 子模块进行可重现的构建(依赖管理)?
- typescript - Map 可以将键作为自定义类型吗?
- mongodb - MongoDB $slice 性能
- wpf - 来自不同窗口的 ShowDialog 中的异常
- scenekit - 在 Scenekit 中,摩擦系数如何在一对材料之间应用
- facebook-graph-api - 我是否需要“公共页面内容”权限才能阅读页面帖子?
- sql - 用一个条件计算分区(/不计算 NULL 值)
- android - Android忽略runOnUiThread中语言文件中的字符串
- codeigniter - Google Recatpcha v2 Invisible 根本不工作说缺少输入响应
- tableview - tableView didset 不重新加载