2

On windows XP x64 (and I assume win2k3) powershell 2.0, passing an arraylist of pscustomobjects to start-job as argumentlist parameter passes the object in but scriptproperties just disappear from the object (confirmed by get-member). Note properties of the pscustomobject do return just fine

Anyone know why? and/or have a solution for a work around?

$dbs is arraylist with pscustomobjects that have various noteproperties and scriptproperties.

All of the script properties disappear once passed into start-job, while note properties work just fine.

Below executed outside of start-job

$dbs | get-member 

returns

ConnectionString NoteProperty   System.String ConnectionString=server=...
DbType           NoteProperty   System.String DbType=Staging                                                                                   
 CreateBackup     ScriptMethod   System.Object CreateBackup ();                                                                                  
GetBackup        ScriptMethod   System.Object GetBackup();                                                                                     

...
while

start-job -name $server -argumentlist $dbs,$server -scriptblock {
    param($dbs, $server)
 $dbs | get-member
 }

Returns

bool Equals(System.Object obj) 
int GetHashCode() 
type GetType() 
string ToString() 
System.String ConnectionString=server=...
System.String DbType=Staging
JorgeSandoval
  • 1,085
  • 1
  • 10
  • 20

2 Answers2

1

Background jobs use remoting. Remoting serializes the objects and then sends them to the target runspace, where they are de-serialized. When an object is serialized, object methods are not included in the serialized object.

mjolinor
  • 66,130
  • 7
  • 114
  • 135
1

Look at Custom PowerShell Host and Converting PSObject back to base type I answered some time ago. It is the same case.

Community
  • 1
  • 1
stej
  • 28,745
  • 11
  • 71
  • 104
  • Thanks, I guess I should have realized it was using PS remoting under the hood and seen the presence of flattened properties as indication of serialization. Its a bit of a bummer given the utility methods on the object will have to be replicated in the script block in order to use them. Thanks! – JorgeSandoval Jul 14 '11 at 21:01