我正在尝试创建对象并使用远程处理对其进行操作,如下所示:
$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 对象,您必须在脚本 block 中包含代码:
$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
关于Powershell 远程处理 - 远程创建对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17362579/