2

我正在尝试创建对象并使用远程处理对其进行操作,如下所示:

$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 对象并对其进行操作?

4

1 回答 1

2

Invoke-Command返回输出,而不是创建的对象。如果要通过远程操作 COM 对象,Invoke-Command则必须在脚本块中包含代码:

$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
于 2013-06-28T10:56:11.477 回答