문제

I am trying to create object and operate on it using remoting as below:

$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)}

My understanding that $newquotaobj would be deserialized and sent back - but it does not seem to happen. Is it even possible to achive my goal here - i.e creating com object remotely and operating on it?

도움이 되었습니까?

해결책

Invoke-Command returns the output, not the objects created. If you want to remotely operate COM objects via Invoke-Command you have to include the code in the script 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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top