问题描述
我正在尝试在高级函数中使用 Invoke-Command 返回带有工作区的对象。
这有效:
$g = Invoke-Command -ComputerName server1,server2,server3 -ScriptBlock {
$AgentCfg = New-Object -ComObject AgentConfigManager.MgmtSvcCfg
$AgentCfg.GetCloudWorkspaces()
}
$g| Measure-Object
这不是,Measure-Object 说有 0 个对象。
function Get-WorkspaceInfo {
[CmdletBinding()]
param(
[string[]]$ComputerName,[string]$ErrorLog
)
BEGIN {}
PROCESS {
foreach ($Computer in $ComputerName) {
write-verbose "$Computer Iteration"
$RemoteWorkspaces = Invoke-Command -ComputerName $Computer -ScriptBlock {
$AgentCfg = New-Object -ComObject AgentConfigManager.MgmtSvcCfg
$OMSWorkspaces = $AgentCfg.GetCloudWorkspaces() }
$RemoteWorkspaces | Measure-Object
}
}
END {}
}
Get-Workspaceinfo -ErrorLog x.txt -ComputerName server1,server3 -Verbose
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)