我正在尝试使用远程处理创建对象并对其进行操作,如下所示:
$foldername = "C:\test"
$computername ="remotecomputer"
Invoke-Command -computername $computername -Scriptblock {$newquotaobj = New-Object -ComObject Fsrm.FsrmQuotaManager}
Invoke-Command -computername $computername -Scriptblock {$newquotasrc = $newquotaobj).GetQuota($Using:foldername)}
我理解$newquotaobj
将被反序列化并发回 - 但似乎并未发生。是否有可能在这里实现我的目标 - 即远程创建com对象并对其进行操作?
答案 0 :(得分:2)
Invoke-Command
返回输出,而不是创建的对象。如果要通过Invoke-Command
远程操作COM对象,则必须在脚本块中包含代码:
$foldername = "C:\test"
$computername ="remotecomputer"
Invoke-Command -ComputerName $computername -ScriptBlock {
$newquotaobj = New-Object -ComObject Fsrm.FsrmQuotaManager
$newquotasrc = $newquotaobj.GetQuota($args[0])
$newquotasrc # <-- this will be returned to the local host
} -ArgumentList $foldername