开发者

Why are script properties lost when passing pscustomobject to start-job script block?

On windows XP x64 (and I assume win2k3) powershell 2.0, passing an arraylist of pscustomo开发者_StackOverflow社区bjects 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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜