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