1

I am working on a PowerShell script that remotely gets veeam Backup reporting data from a backup server. I know we can pass variables usually with $Using:

$object = Invoke-command -ComputerName serverName -ScriptBlock { Get-VBRBackup | Where-Object { $_.JobName -eq $Using:jobName }}

but how can I call method of the object, I tried as below and doesn't work.

$data=Invoke-command -ComputerName serverName -ScriptBlock { $($using:object).GetLocalStorages()}

but if I do : $data=Invoke-command -ComputerName serverName -ScriptBlock { $(Get-VBRBackup | Where-Object { $_.JobName -eq $Using:jobName }}).GetLocalStorages()} it works:

I am quite new to PowerShell and don't know much. How to encapsulate alocal objects in invoke-command and call its method?

Manoj Rai
  • 81
  • 1
  • 6
  • 2
    "However, the deserialized object is not a live object. It is a snapshot of the object at the time that it was serialized, and it includes properties but no methods." From: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_remote_output?view=powershell-7.2#deserialized-objects – Santiago Squarzon Mar 10 '22 at 00:00
  • 1
    Santiago pretty much covers it. When dealing with remote objects, the entirety of the object itself becomes *deserialized* once brought back and stored in your computer's memory. Meaning, you cannot call on any of the previous methods exposed onto the object itself if it's not invoked as you've showed in your 2nd example. – Abraham Zinala Mar 10 '22 at 00:10
  • 1
    @SantiagoSquarzon Thanks, a good insight into PowerShell remote objects. I had no idea about live objects but makes sense. Have to revisit some of my codes. Thanks for the link too, it is right on. – Manoj Rai Mar 10 '22 at 00:21
  • If you want to replicate the same behavior without using `Invoke-Command` you can do `$newobject = [System.Management.Automation.PSSerializer]::Deserialize([System.Management.Automation.PSSerializer]::Serialize($object))` after that you will notice that `$newobject` will no longer have it's methods – Santiago Squarzon Mar 10 '22 at 00:23

0 Answers0