我有一个在远程机器上安装远程桌面服务的脚本(从DC)。
我现在处于检查RDS是否安装在连接代理(服务器)和连接主机(服务器)上的阶段。
我想使用invoke-command,因为远程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但我的问题是,如何将scriptblock的输出封装在调用命令中的DC可以访问的变量中?如果RDS安装成功或无法写入日志文件,我正在尝试写出
我们如何封装函数的输出,并将其传递给运行它的机器?
谢谢
发布于 2017-03-03 21:25:54
通常,要让powershell从命令\函数返回某些内容,您可以生成任何类型的输出。因此,只要在代码中输入"bla-bla“,就会向调用者返回"bla-bla”。这样,您的案例就简化了:
$res = Invoke-Command -ComputerName "testpc.eil.local" -ScriptBlock {
(Get-WindowsFeature -Name "Remote-Desktop-Services").Installed
}
do something with $res herehttps://stackoverflow.com/questions/42580034
复制相似问题