【发布时间】:2017-07-23 15:09:41
【问题描述】:
我有一个脚本可以在远程机器上安装远程桌面服务(来自 DC)。
我现在处于检查 RDS 是否安装在连接代理(服务器)和连接主机(服务器)上的阶段。
我想使用调用命令,因为远程 powershell 会话似乎太复杂了。
这是我的代码:
$res = Invoke-Command -ComputerName "testpc.eil.local" -ScriptBlock {
if((Get-WindowsFeature -Name "Remote-Desktop-Services").Installed -eq 1)
{
#i need this output (true or false or a string)
}
else
{
#i need this output (true or false or a string)
}
}
Write-Host $res
但我的问题是,如何将调用命令中脚本块的输出封装在 DC 可以访问的变量中?如果 RDS 成功安装或未能写入日志文件,我正在尝试写掉
我们如何封装函数的输出并将其传递给运行它的机器?
谢谢
【问题讨论】:
标签: powershell variables scripting invoke-command storing-data