我正在尝试创建对象,并使用远程处理对其进行如下操作:
$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对象并对其进行操作? 最佳答案
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